How to populate a VB Windows form Grid with an xml document(Data source)

I am working with VB .Net for windows forms applications. Not web applications. What I need to do is to the out of the box VB.net Grid control with an XML data source. The xml data source is just an xml file that will equate to two columns of data in the GridView.
Now I can find plenty of examples on the web which will populate a .NET Grid for a web application, but not for a desktop windows form application. Can anyone tell me how to do this?
LVL 2
brgdotnetcontractorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Naitik GamitSoftware DeveloperCommented:
Look at this microsoft support blog for: Read XML Data into a DataSet by Using Visual Basic .NET

https://support.microsoft.com/en-us/kb/309702
0
Fernando SotoRetiredCommented:
Hi brgdotnet;

Here is an example of using an XML document to Fill a DataGridView.

Test XML Document
<?xml version='1.0' encoding='UTF-8' ?>
<books>
  <book title="Windows Forms in Action">
    <publisher>Manning</publisher>
  </book>
  <book title="RSS and Atom in Action">
    <publisher>Manning</publisher>
  </book>
  <book title="Understanding and Using C Pointers">
    <publisher> O'Reilly</publisher>
  </book>
</books>

Open in new window

Using this VB code
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
     '' Change the path and file name to match where you loaded the document
     Dim xdoc As XDocument = XDocument.Load("C:\Working Directory\Books.xml")

     Dim books = (From book In xdoc.Root.Descendants("book")
                  Select New With
                  {
                      .Title = book.Attribute("title").Value,
                      .Publisher = book.Element("publisher").Value
                  }).ToList()

     DataGridView1.DataSource = books

End Sub

Open in new window

Will result in this.
DataGridView Results
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brgdotnetcontractorAuthor Commented:
Thank you Fernando
0
Fernando SotoRetiredCommented:
Not a problem brgdotnet, glad to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.