What is going wrong with this simple CODE "loading names into a listbox"

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim doc = XDocument.Load(myPath)
        lstMem.Items.Clear()
        For Each item In doc...<Contact>
            lstMem.Items.Add(item.@Fname & " " & item.@Lname)
        Next

    End Sub

This opens a simple XML parses it and returns the names in the listbox
However no matter if I close the app and reopen it .... I get a space in the listbox like this

It should return this
John Doe
Jane Doe
Jim Smith
Jene Smith
Sally Somebody

BUT I get this
John Doe
                <------ Note the empty space
Jane Doe
Jim Smith
Jene Smith
Sally Somebody

Now one thing you might should know I had another name but deleted it using this code
Dim doc = XDocument.Load(myPath)

        Dim remCon = From rC In doc.<AddBook>.<Contact> _
                     Where rC.@Fname = txtfName.Text _
                     Where rC.@Lname = txtLname.Text _
                     Select rC

        For Each itm In remCon
            itm.RemoveAll()
        Next

        doc.Save(myPath)

I closed the app re opened it and I get the space like it is remembering where the record was I deleted ... its crazy ...
I check the xml file ... the node and its children are gone as they should be ... I even re saved the xml file and it still does it when I open the app

This is totally got me stumped here guys
vbMarkOAsked:
Who is Participating?
 
vbighamConnect With a Mentor Commented:
I think when you call itm.RemoveAll(), it is saying "remove all the inner contents of this node".  

I am guessing that what you want is itm.Remove(), for which the documentation reads: "Removes this node from its parent."

Check this link for more details:
http://msdn.microsoft.com/en-us/library/system.xml.linq.xelement.aspx

Best of Luck.
0
 
vbMarkOAuthor Commented:
Arrrrrgh I think I found it
In the XML file when it deletes the Node and its children its not getting everything it leaves this

  <Contact />
So its reading that when it loads .. so the question is why isnt my code deleting everything then????
0
 
vbMarkOAuthor Commented:
Yep that did it ... thanx a million

I so appreciate it!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.