Connecting Tech Pros Worldwide Forums | Help | Site Map

Searching XML adding found item to DataGridView

Member
 
Join Date: Dec 2007
Posts: 121
#1: Jul 23 '09
Hello Folks,
I am searching a XML file for <Asset_Number> and then
adding all children to DataGridView1,
i can search but i dont know how to add item to the DataGridView
Also my datagridview columns are created from a txt file


this is what i have.....

this is my XML
<?xml version="1.0" standalone="yes"?>
<DocumentElement>
<items>
<Description>Description</Description>
<Asset_Number>Asset Number</Asset_Number>
<Asset_Type>Asset Type</Asset_Type>
<Location>Location</Location>
</items>
<items>
<Description>Laminator</Description>
<Asset_Number>MOA81</Asset_Number>
<Asset_Type>Electrical</Asset_Type>
<Location>ADMINISTRATION OFFICE</Location>
</items>
</DocumentElement>

Expand|Select|Wrap|Line Numbers
  1.     Dim items As DataSet = New DataSet()
  2.     Dim count As Integer
  3.     Dim a As Integer
Expand|Select|Wrap|Line Numbers
  1.         items.ReadXml((Application.StartupPath) & "\electrical_DB.xml", XmlReadMode.Auto)
  2.         count = items.Tables(0).Rows.Count
  3.         Call find()
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         'XML search
  3.         Dim b As Integer
  4.         For b = 0 To (count - 1)
  5.             If items.Tables(0).Rows(b).Item("Asset_Number").ToString.ToUpper Like ((txtBarCode.Text.ToUpper) & "*") Then
  6.                 a = b
  7.                 Call find()
  8.                 Exit For
  9.             End If
  10.         Next
  11.     End Sub
Expand|Select|Wrap|Line Numbers
  1.     Sub find()
  2.         'this is where im stuck
  3.         'i want the whole found node displayed in DataGridView1
  4.         ' but this doesnt work
  5.         DataGridView1.datasource = items.Tables(0).Rows(a).Item("Asset_Number")
  6.     End Sub
any help would be greatly appreciated , please forgive me as i am just
learning
Thanks in advanced
Gobble.

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#2: Jul 27 '09

re: Searching XML adding found item to DataGridView


While looking into your problem I came an interesting fact that I was unaware of until now. Apparently you can use ADO.NET to fill a DataSet. Check out this article for more information.

A DataSet contains a bunch of tables. A table can be used as a data source for the DataGridView control....

I've never done this before myself, but you should look into whether or not XSL can help you to filter the XML results into what you want.

-Frinny
Reply

Tags
datagridview, search, xml