Question Using DataGridView to View/Edit XML

jsurpless

Well-known member
Joined
Jul 29, 2008
Messages
144
Programming Experience
Beginner
Hi all

I'm pretty new to VB.net programming - most of my experience is in VBA Office 2k3 - and I was hoping I've got a pretty easy question...

I've got an XML file that I'd like to display on a form... looking into this a bit, it seems that I'd want to use a DataGridView... so far, I've been able to read the XML into it but I can't quite figure out how to perform edits within the View and then write those out back to the XML...

Here's what I've done so far...

VB.NET:
    Private Sub MatchMakerXML_Editor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        XMLFilePath.Text = c_MatchMakerXML.XMLFilePath

        Dim MatchMakerXML_Dataset As New DataSet

        MatchMakerXML_Dataset.ReadXml(c_MatchMakerXML.XMLFilePath)

        XMLGridView.DataSource = MatchMakerXML_Dataset.Tables(0)

    End Sub

Can someone explain to me why reading the ".Tables(0)" is necessary? I've seen examples without it, so I'm curious... here's my XML file...

VB.NET:
<MATCHLIST>
<MATCH>
<AUTOCAD>UNIT</AUTOCAD>
<DATABASE>UNIT</DATABASE>
</MATCH>
<MATCH>
<AUTOCAD>UNIT</AUTOCAD>
<DATABASE>UNIT</DATABASE>
</MATCH>
</MATCHLIST>

Looking around, I've seen references to GridView_RowUpdating but I guess this doesn't apply to VB.Net?

Many thanks in advance!

-Justin
 
If you want to ensure that drawing_match is read only then:

Make the datagridview readonly that displays it
Call MyDataSet.Tables("DRAWING_MATCH").RejectChanges() before you write the file
 
When you assign Dataset to Datasource only a reference is set, so they both point to the same dataset, whichever reference you use you get the same object. Read help topic Value Types and Reference Types.

I figured it must be some sort of reference arrangement...

Thanks
If you want to ensure that drawing_match is read only then:

Make the datagridview readonly that displays it
Call MyDataSet.Tables("DRAWING_MATCH").RejectChanges() before you write the file

Hi

Not looking to prevent changes was just unsure why it was implementing changes that it didn't seem like I was... thanks for the suggestion, though...
 
Hi

I've got another XML question... I'd like to loop through the entries in my XML file that correspond to the datagridview... here's what the data looks like

VB.NET:
  <DrawingBorderBlocks>
    <Block>TITLE_06</Block>
  </DrawingBorderBlocks>
  <DrawingBorderBlocks>
    <Block>NOTEBX</Block>
  </DrawingBorderBlocks>
  <DrawingBorderBlocks>
    <Block>REFBX</Block>
  </DrawingBorderBlocks>
  <DrawingBorderBlocks>
    <Block>REVBX</Block>
  </DrawingBorderBlocks>
  <DrawingBorderBlocks>
    <Block>TITLEBX</Block>
  </DrawingBorderBlocks>

My datagridview is set to look at 'DrawingBorderBlocks'... as I understand it, they're all part of the same node... how can I loop through those entries to extract the .Innertext?

Thanks!
 
Back
Top