Adding controls to a windows from from XML
-
Hey howzit, i have a method below that loops through an XML document and adds textbox and checkbox controls to a panel based on the xml content. However the performance is not great all at...one can see all the controls are they are being displayed and it looks sloppy...is there not a better way of doing this? public void DeSerialize(XmlDocument xmlDoc, int currentPage) { XmlNode rootNode = xmlDoc.DocumentElement; foreach (XmlNode pageNode in rootNode.ChildNodes) { XmlAttributeCollection acPage; acPage = pageNode.Attributes; int pg = Convert.ToInt32(Convert.ToDouble(acPage.Item(0).InnerText)); if (pg==currentPage) { foreach (XmlNode fieldNode in pageNode.ChildNodes) { if (fieldNode["Type"].InnerText == "TextBox") { //create and add textbox to windows.forms.controls } else if (fieldNode["Type"].InnerText == "CheckBox") { //create and add checkbox to windows.forms.controls } } } } }
-
Hey howzit, i have a method below that loops through an XML document and adds textbox and checkbox controls to a panel based on the xml content. However the performance is not great all at...one can see all the controls are they are being displayed and it looks sloppy...is there not a better way of doing this? public void DeSerialize(XmlDocument xmlDoc, int currentPage) { XmlNode rootNode = xmlDoc.DocumentElement; foreach (XmlNode pageNode in rootNode.ChildNodes) { XmlAttributeCollection acPage; acPage = pageNode.Attributes; int pg = Convert.ToInt32(Convert.ToDouble(acPage.Item(0).InnerText)); if (pg==currentPage) { foreach (XmlNode fieldNode in pageNode.ChildNodes) { if (fieldNode["Type"].InnerText == "TextBox") { //create and add textbox to windows.forms.controls } else if (fieldNode["Type"].InnerText == "CheckBox") { //create and add checkbox to windows.forms.controls } } } } }
how about, hide the panel then add the controls then show the panel? Might stop the visual sloppiness! Also, seeing as you only need fast forward read access to your XML then you could use an XmlTextReader instead of the DOM implemntation (which allows read/write access and is unnecessary overhead if you want speed)
-
Hey howzit, i have a method below that loops through an XML document and adds textbox and checkbox controls to a panel based on the xml content. However the performance is not great all at...one can see all the controls are they are being displayed and it looks sloppy...is there not a better way of doing this? public void DeSerialize(XmlDocument xmlDoc, int currentPage) { XmlNode rootNode = xmlDoc.DocumentElement; foreach (XmlNode pageNode in rootNode.ChildNodes) { XmlAttributeCollection acPage; acPage = pageNode.Attributes; int pg = Convert.ToInt32(Convert.ToDouble(acPage.Item(0).InnerText)); if (pg==currentPage) { foreach (XmlNode fieldNode in pageNode.ChildNodes) { if (fieldNode["Type"].InnerText == "TextBox") { //create and add textbox to windows.forms.controls } else if (fieldNode["Type"].InnerText == "CheckBox") { //create and add checkbox to windows.forms.controls } } } } }
Hi You could try using
SuspendLayout
. ---------------------------- Be excellent to each other :) EasiReports[^] My free reporting component for WinForms.