xml - C#: Why is this code populating this listView out of order? -


I am what where no one could see that I was wrong? Code should create an XML document, then, depending on the content of each node, to populate the columns of a ListView with the text within each node / attribute. List View should look like this:

  before 1 ITEM2 ITEM3 Item4 Item5 Item6 Item7 Item8 Item9   

Although this eliminated:

  Item7 ITEM2 Item5 Item4 before 1   

the production code of this error:

  private void openPasswordFileToolStripMenuItem_Click (object sender, EventArgs e) {System.Xml.XmlDocument loadDoc = New System.Xml.XmlDocument (); LoadDoc.Load (application.StartupPath + "\\ database.xml"); foreach (System.Xml.XmlNode descNode ( "/ database / Account") in loadDoc.SelectNodes) {lvItem = listView1.Items.Insert (index, descNode.Attributes [ "description"] innerText.); ; } Foreach (System.Xml.XmlNode userNode ( "/ database / Account") in loadDoc.SelectNodes) {lvItem.SubItems.Add (New ListViewItem.ListViewSubItem (lvItem, userNode.Attributes [ "username"] innerText).); ; } Foreach (System.Xml.XmlNode passNode ( "/ database / Account") in loadDoc.SelectNodes) {lvItem.SubItems.Add (New ListViewItem.ListViewSubItem (lvItem, passNode.Attributes [ "password"] innerText).); ; } Foreach (system.xml.xmlNode in node loadload) {index + = 1; }}    

Not sure about the structure of XML documents, but my foreach code Is wrong If you are trying to add sub-items for every parent

  foreach (System.Xml.XmlNode descNode in loadDoc.SelectNodes ( "/ database / account")) {lvItem = ListView1.Items. Insert (index, descNode.Attributes ["description"] .intertext;); ; lvItem.SubItems.Add (New ListViewItem.ListViewSubItem (lvItem, userNode.Attributes [ "username"] innerText).); ; lvItem.SubItems.Add (New ListViewItem.ListViewSubItem (lvItem, passNode.Attributes [ "password"] innerText).); ; }    

Comments