Loading XML data into ListView control
-
I have googled for 2 days straight with no success... Scenario: Load simple xml data into listview control with 2 or more columns. I have used XmlTextReader and XmlReader with very limited success. I am able to populate the listview but only the first column. If someone could point me in the right direction, I would greatly appreciate it. --Steve
-
I have googled for 2 days straight with no success... Scenario: Load simple xml data into listview control with 2 or more columns. I have used XmlTextReader and XmlReader with very limited success. I am able to populate the listview but only the first column. If someone could point me in the right direction, I would greatly appreciate it. --Steve
I would suggest investigating how to create a DataTable and populate it with your xml. This will not be an easy task but it's by no means overly difficult either. It will just take a bit of work to accomplish. You will have to create each column in the DataTable and fill it with the appropriate data. Once that's done you can bind the DataTable to the ListView and you should be good to go. There may be a way to cut out the DataTable entirely but you may figure that out by researching what I suggested.
- Arcond
-
I have googled for 2 days straight with no success... Scenario: Load simple xml data into listview control with 2 or more columns. I have used XmlTextReader and XmlReader with very limited success. I am able to populate the listview but only the first column. If someone could point me in the right direction, I would greatly appreciate it. --Steve
Go figure: I post my question and then I find my answer. Answer lies with XmlDocument. See code snippet below. My xml file (checklist.xml) is really an index used for parsing files of their data based on a starting point, string size, and a description. In turn these are my columns in my listview control as well.
private void tsbtnRunAudit_Click( object sender, EventArgs e ) { XmlDocument xdoc = new XmlDocument(); xdoc.Load(@"C:\DEVELOPMENT\Sandbox\VikConvAudit\VikConvAudit\Indexes\checklist.xml"); XmlNodeList start = xdoc.GetElementsByTagName("Start"); XmlNodeList size = xdoc.GetElementsByTagName("Size"); XmlNodeList description = xdoc.GetElementsByTagName("Description"); for(int i = 0; i < start.Count; i++) { lvMain.Items.Add(start[i].InnerText); lvMain.Items[i].SubItems.Add(size[i].InnerText); lvMain.Items[i].SubItems.Add(description[i].InnerText); } }