2 Replies - 953 Views - Last Post: 07 March 2013 - 09:49 AM Rate Topic: -----

#1 John11  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 17-March 12

How to add DataGridView row using XML Element

Posted 07 March 2013 - 09:17 AM

Hello, I have an XML file 'Logs.xml' which goes like this:
<?xml version="1.0" encoding="utf-8"?>
<Logs>
<Log ID="" Client_ID="" Mac_ID="" Date_ID="" In="" Out="" Welcome="" Bonus="" Award="" CreditIN="" CreditOUT="0" />
....
</Logs>

I want to add a row to DataGridView1 using this XML file.
I have the code below

 Dim doc As New XmlDocument
        doc.Load(Application.StartupPath & "\Files\Logs.xml")
        For Each element As XmlElement In doc.DocumentElement
            If element.Attributes.ItemOf("Client_ID").Value = cmbFullName.Text And (CDate(element.Attributes.ItemOf("Date_ID").Value) >= DateTimePickerFROM.Value And CDate(element.Attributes.ItemOf("Date_ID").Value) < DateTimePickerTO.Value) Then
'Add some attribues of this element to Datagridview 1
            End If
        Next



Is there a way to add some attributes of the element i'm searching for in the datagridview ?
and btw I'm new to xml.

Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: How to add DataGridView row using XML Element

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: How to add DataGridView row using XML Element

Posted 07 March 2013 - 09:46 AM

If you're manually adding rows you would typically use

Datagridview1.Rows.Add(column1data, column2data, column3data etc...)

I would think you could use the ItemOf("attribute") where they need to be

Something like:
DataGridView1.Rows.Add(element.attributs.itemof("Client_ID").Value),element.attributes.itemof("SomeOtherAttribute").Value)


This would populate the dgv with those values in the first two columns for the current element
Was This Post Helpful? 0
  • +
  • -

#3 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,057
  • Joined: 02-July 08

Re: How to add DataGridView row using XML Element

Posted 07 March 2013 - 09:49 AM

The other thing that you can try(if your xml is formatted right) you can make a DataSet and use the .ReadXml() method. Then you bind the DGV to the first table in the DataSet.

This post has been edited by _HAWK_: 07 March 2013 - 09:49 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1