Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

help populating a vb.net dataGrid with a table from XML

Hi...i just want to load a dataGrid with a table in my XML doc.  i just need to know if i need to change my XML, my VB.NET code or both and how......thanks!  all the details are below; if i 've forgotten anything, just ask please!

XML CODE snippet:
<Characters>
      <character id="0" type="PC" name="Nathan Baros" realName="Craig Pierce">
            <skills>
                <skill name="climb" level="6" />
                <skill name="sit" level="10" />
                <skill name="stand" level="2" />
            </skills>
      </character>
      <character id="0" type="PC" name="Todd Myres" realName="Josh">
            <skills>
                  <skill name="falldown" level="6" />
                  <skill name="guitar" level="6" />
            </skills>
      </character>
</Characters>

VB.NET CODE snippet:
charactersDS.ReadXml("C:\Characters.xml", XmlReadMode.InferSchema)
charactersDT = charactersDS.Tables("character")

QUESTION:
when i say *charactersDT = charactersDS.Tables("character")* i can then refer to each 'character' as a row....as in  *RealNameTextBox.Text = charactersDT.Rows(RowNumber).Item("realName")*

each character's stats will go into text boxes using lines just like that one.  then i have a dataGrid that i'm trying to place the skills into.  i can make the dataGrid display ALL of the skills for EVERY character with "Name" and "Level" columns at the top and the skills listed in the rows.....using this code:

Dim skillsDT As DataTable
skillsDT = charactersDS.Tables("skill")
DataGridView1.DataSource = skillsDT

that grabs every 'skill' for every 'character' in the XML document; however, i only want to display the skills of ONE character at a time.

is there a way that i can specify one dataTable to consist of only the 3 skills for Nathan Baros and another dataTable to consist of only the 2 skills for Todd Myres??  can i somehow specify which row(i.e. character) i want to take the skills from?  (i.e. only the skills from charactersDT.Rows(RowNumber))

Note:  i am using a dataListView and listing all the characters in that listView....then, when you select one character, i want that one character's skills to appear in the dataGrid.

please Help!  this is driving me nuts......thanks.
0
craigpierce
Asked:
craigpierce
1 Solution
 
RonaldBiemansCommented:
Hi graigpierce, This work I have changed the xml file a bit (I didn't see the use of the skills)

like

<Characters>
      <character id="0" type="PC" name="Nathan Baros" realName="Craig Pierce">
           <skill name="climb" level="6" />
           <skill name="sit" level="10" />
           <skill name="stand" level="2" />
      </character>
      <character id="1" type="PC" name="Todd Myres" realName="Josh">
           <skill name="falldown" level="6" />
           <skill name="guitar" level="6" />
      </character>
</Characters>



if you want just to show the skills of Todd Myres, do something like this

        Dim DS As New DataSet
        DS.ReadXml("C:\ttt.xml", XmlReadMode.InferSchema)
        DataGrid1.DataSource = DS.Tables(0)
        Dim dv As DataView = DS.Tables(1).DefaultView
        dv.Sort = "Character_id"
        dv.RowFilter = "Character_id = 1"
        DataGrid2.DataSource = dv
0
 
craigpierceAuthor Commented:
thank you!  that was easy (as i knew it had to be)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now