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

Posted on 2011-10-10
Medium Priority
Last Modified: 2012-05-12
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

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

    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


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
Question by:vbMarkO
  • 2

Author Comment

ID: 36943382
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????

Accepted Solution

vbigham earned 2000 total points
ID: 36943596
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:

Best of Luck.

Author Closing Comment

ID: 36943617
Yep that did it ... thanx a million

I so appreciate it!!!

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question