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 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?
Who is Participating?
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' ?>
  <book title="Windows Forms in Action">
  <book title="RSS and Atom in Action">
  <book title="Understanding and Using C Pointers">
    <publisher> O'Reilly</publisher>

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

     DataGridView1.DataSource = books

End Sub

Open in new window

Will result in this.
DataGridView Results
Naitik GamitSoftware DeveloperCommented:
Look at this microsoft support blog for: Read XML Data into a DataSet by Using Visual Basic .NET
brgdotnetcontractorAuthor Commented:
Thank you Fernando
Fernando SotoRetiredCommented:
Not a problem brgdotnet, glad to help.
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.