Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

How update xml file based on values selected from a data grid?

Avatar of vcharles
vcharles asked on
5 Comments1 Solution659 ViewsLast Modified:
Subject:  How update xml file based on values selected from a data grid?


I’m using the code in below (Section A) to update data in my “link.xml” using a combo box with my grid control, the problem is I can’t figure out how to save the data modified to the xml file, below (Section B) is the code I use to save new data to the xml file, can you please help me modify the code in section B to only save the rows modified?



Section A.

dtLink = New DataTable("Link")

        Dim linker As XElement = XElement.Load(Application.StartupPath + "\Link.xml")
        For Each item As XElement In linker.Elements("Row")
            Dim linkID As String = item.Element("Link_ID").Value
            Dim CtryDeveloperID As String = item.Element("WDeveloper_ID").Value
            Dim CtryUserID As String = item.Element("WUser_ID").Value
            Dim DInventoryID As String = item.Element("DInventory_ID").Value
            Dim drLink As DataRow = dtLink.NewRow()
            drLink("Link_ID") = linkID
            drLink("WDeveloper_ID") = CtryDeveloperID
            drLink("WUser_ID") = CtryUserID
            drLink("DInventory_ID") = DInventoryID

        Dim bs As New BindingSource()
        bs.DataSource = dtLink
        C1TrueDBGrid1.DataSource = bs
        C1TrueDBGrid1.AlternatingRows = True
        C1TrueDBGrid1.Caption = "Inventory Charts"
        Me.C1TrueDBGrid1.Splits(0).DisplayColumns(0).Width = Me.C1TrueDBGrid1.Splits(0).DisplayColumns(0).Visible = False

        Dim vReceiverDev As C1.Win.C1TrueDBGrid.ValueItemCollection
        Dim vReceiverUsr As C1.Win.C1TrueDBGrid.ValueItemCollection
        vReceiverDev = Me.C1TrueDBGrid1.Columns("WDeveloper_ID").ValueItems.Values
        vReceiverUsr = Me.C1TrueDBGrid1.Columns("WUser_ID").ValueItems.Values

        Dim WCtryDeveloper As XElement = XElement.Load(Application.StartupPath + "\Receiver.xml")

        For Each item As XElement In WCtryDeveloper.Elements("Row")
            Dim receiverID As String = item.Element("Receiver_ID").Value
            Dim receiverName As String = item.Element("Receiver").Value

            vReceiverDev.Add(New C1.Win.C1TrueDBGrid.ValueItem(receiverID, receiverName))
            vReceiverUsr.Add(New C1.Win.C1TrueDBGrid.ValueItem(receiverID, receiverName))

        Me.C1TrueDBGrid1.Columns("WDeveloper_ID").ValueItems.Translate = True
        Me.C1TrueDBGrid1.Columns("WDeveloper_ID").ValueItems.Presentation = C1.Win.C1TrueDBGrid.PresentationEnum.ComboBox
        Me.C1TrueDBGrid1.Columns("WUser_ID").ValueItems.Translate = True
        Me.C1TrueDBGrid1.Columns("WUser_ID").ValueItems.Presentation = C1.Win.C1TrueDBGrid.PresentationEnum.ComboBox

        Dim vInventory As C1.Win.C1TrueDBGrid.ValueItemCollection
        vInventory = Me.C1TrueDBGrid1.Columns("DInventory_ID").ValueItems.Values

        Dim DInventory As XElement = XElement.Load(Application.StartupPath + "\Inventory.xml")

        For Each item As XElement In DInventory.Elements("Row")
            Dim inventoryID As String = item.Element("Inventory_ID").Value
            Dim inventoryName As String = item.Element("Inventory").Value

            vInventory.Add(New C1.Win.C1TrueDBGrid.ValueItem(inventoryID, inventoryName))


        Me.C1TrueDBGrid1.Columns("DInventory_ID").ValueItems.Translate = True
        Me.C1TrueDBGrid1.Columns("DInventory_ID").ValueItems.Presentation = C1.Win.C1TrueDBGrid.PresentationEnum.ComboBox

Section B.

            Dim ds As New DataSet
            ds.ReadXml(Application.StartupPath + "\Link.xml")
            Dim dt As DataTable = ds.Tables(0)
            Dim r As DataRow = dt.NewRow
            r!Link_ID = dt.Rows(dt.Rows.Count - 1)("Link_ID") + 1
            r!WDeveloper_ID = C1TrueDBGrid42.Columns(0).Value
            r!WUser_ID = C1TrueDBGrid43.Columns(0).Value
            r!DInventory_ID = C1TrueDBGrid44.Columns(0).Value
            ds.WriteXml(Application.StartupPath + "\Link.xml")

        Catch ex As Exception
            MsgBox("Items selected were not saved", MsgBoxStyle.OkOnly, "Confirmation")
            Exit Sub
        End Try

Avatar of vcharles

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answers