[RESOLVED] J#.NET - XML -> ListBox
I am using VJ#.NET to make an application, and I am needing to read an XML file into a list box and then be able to rip out other elements from this XML file later.
An example from this XML file is:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<itemdb>
<item name="Dwarf remains" description="The body of a Dwarf savaged by Goblins." type="0" members="true"/>
<item name="Tool kit" description="These could be handy." type="1" members="true"/>
I won't post the whole file, as it is over 6000 lines long.
I want to read this XML file, and then insert each <item> element's "name" attribute into a listbox named listBox1
How would I go about this? So far I have this:
VB Code:
DataSet dsItems = new DataSet("DataGrid");
String filePath = "Items.xml";
dsItems.ReadXml(filePath);
dataGrid1.set_DataSource(dsItems);
dataGrid1.set_DataMember("item");
dataGrid1.set_CaptionText(dataGrid1.get_DataMember());
Would I need the dataGrid to be able to do this? It outputs it perfectly fine into the dataGrid.
Re: J#.NET - XML -> ListBox
Specify what Table, not a DataSet. Also set the DisplayMember as the attribute you want to display.
DataSet ds=new DataSet();
ds.ReadXml("Items.xml");
listBox1.set_DataSource(ds.get_Tables().get_Item(0));
listBox1.set_DisplayMember("name");
Re: J#.NET - XML -> ListBox
Quote:
Originally Posted by nebulom
Specify what Table, not a DataSet. Also set the DisplayMember as the attribute you want to display.
DataSet ds=new DataSet();
ds.ReadXml("Items.xml");
listBox1.set_DataSource(ds.get_Tables().get_Item(0));
listBox1.set_DisplayMember("name");
Thanks. That worked very well. I've been studying that code trying to work out how I could read another value into a string, but I can't seem to work it out.
Re: J#.NET - XML -> ListBox
Quote:
Originally Posted by vixxen2
Thanks. That worked very well. I've been studying that code trying to work out how I could read another value into a string, but I can't seem to work it out.
I'm sorry to tell you I may not understand the last part of your reply. Is that for another problem? Also, can you rephrase it? We maybe can help.
Re: J#.NET - XML -> ListBox
yeah I don't understand too.
Re: J#.NET - XML -> ListBox
Well, now it is reading all the right values into the listbox, I am wanting to be able to choose an item on the list box, and when you choose it, then label3 will change to give the correct information, which would be read from the "description" part of the <item>.
Any ideas? :\
Re: J#.NET - XML -> ListBox
Something like this
DataTable t=ds.get_Tables().get_Item(0);
DataRow r=t.get_Rows().get_Item(listBox1.get_SelectedIndex());
MessageBox.Show(r.get_Item(1).toString());
Re: J#.NET - XML -> ListBox