Searching XML adding found item to DataGridView

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gobblegob
    New Member
    • Dec 2007
    • 133

    Searching XML adding found item to DataGridView

    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 "?>
    <DocumentElemen t>
    <items>
    <Description>De scription</Description>
    <Asset_Number>A sset Number</Asset_Number>
    <Asset_Type>Ass et Type</Asset_Type>
    <Location>Locat ion</Location>
    </items>
    <items>
    <Description>La minator</Description>
    <Asset_Number>M OA81</Asset_Number>
    <Asset_Type>Ele ctrical</Asset_Type>
    <Location>ADMIN ISTRATION OFFICE</Location>
    </items>
    </DocumentElement >

    Code:
        Dim items As DataSet = New DataSet()
        Dim count As Integer
        Dim a As Integer
    Code:
            items.ReadXml((Application.StartupPath) & "\electrical_DB.xml", XmlReadMode.Auto)
            count = items.Tables(0).Rows.Count
            Call find()
    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            'XML search
            Dim b As Integer
            For b = 0 To (count - 1)
                If items.Tables(0).Rows(b).Item("Asset_Number").ToString.ToUpper Like ((txtBarCode.Text.ToUpper) & "*") Then
                    a = b
                    Call find()
                    Exit For
                End If
            Next
        End Sub
    Code:
        Sub find()
            'this is where im stuck
            'i want the whole found node displayed in DataGridView1
            ' but this doesnt work
            DataGridView1.datasource = items.Tables(0).Rows(a).Item("Asset_Number")
        End Sub
    any help would be greatly appreciated , please forgive me as i am just
    learning
    Thanks in advanced
    Gobble.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    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

    Comment

    Working...