Link to home
Start Free TrialLog in
Avatar of Inward_Spiral
Inward_Spiral

asked on

Reading in XML to a datagrid, and then writing it back out again.

I'm working on a simple app that is to read in XML files, and display them in a two-column datagrid(One column for the node name, the other for the data).

Whoever uses the app needs to be able to modify the data in the grid if they want, then press a button to write it out again.

Reading XML into a file isn't a problem, I can store the data in a node list. But for this to work, I think I need a global datagrid, and my experience in using those are next to nothing.

So, I guess my question is, does anyone have any examples of reading data into a global datagrid, then writing it back out again? General knowledge of how to use these would be welcome too, I don't have it down yet.

Any suggestions are appreciated.
Avatar of julman_16
julman_16

Are you working in ASP or Windows client?
What is your framework (.NET or Win2K and such)?
Avatar of Inward_Spiral

ASKER

Working out of Visual Studio .NET.

I haven't been able to get simple tables to work by themselves yet, either. Here's what I tried so far with the DataGrid:

Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles DataGrid1.Navigate

        Dim mDataTable As New DataTable

        mDataTable.Columns.Add("col1")
        mDataTable.Columns.Add("Col2")

        For i As Integer = 0 To 10
            mDataTable.Rows.Add(New String() {"Row " & i, "Data " & i})
        Next

        Me.DataGrid1.DataSource = mDataTable
    End Sub

Okay, I've been able to feed my stuff into a datagrid now, and I can edit the information once it is displayed in the table.

Bear with me on this...how do I save the data out of the table as strings?
I figured out how to add them, but I'm not seeing exactly how they are stored.
Alright, I figured it out. It wasn't too pretty, but it worked for what I need.
Anyone who's interested, here's how I read data into the table and into the datagrid:

    Dim mDataTable As New DataTable
    Dim NodeNames(), NodeVals() as String 'Populate the arrays with whatever you need

            mDataTable.Columns.Add("Node Name")
            mDataTable.Columns.Add("Node Value")

            For i = 0 To (NodeVals.Length - 1)
                mDataTable.Rows.Add(New String() {NodeNames(i), NodeVals(i)})
            Next

            Me.DataGrid1.DataSource = mDataTable

And to save it back out:

           Dim mData as DataTable = mDataTable
   
           For i=0 to (NodeVals.Length - 1)
                 NodeVals(i) = mData.Rows.Item(i).Item(1)
                 NodeNames(i) = mData.Rows.Item(i).Item(0)
           Next


ASKER CERTIFIED SOLUTION
Avatar of SpazMODic
SpazMODic

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial