|
-
Jul 12th, 2005, 05:02 AM
#1
Thread Starter
New Member
[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.
-
Jul 12th, 2005, 08:39 PM
#2
Fanatic Member
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");
-
Jul 13th, 2005, 03:45 AM
#3
Thread Starter
New Member
Re: J#.NET - XML -> ListBox
 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.
-
Jul 13th, 2005, 07:41 PM
#4
Fanatic Member
Re: J#.NET - XML -> ListBox
 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.
-
Jul 13th, 2005, 09:52 PM
#5
Re: J#.NET - XML -> ListBox
yeah I don't understand too.
-
Jul 14th, 2005, 03:28 AM
#6
Thread Starter
New Member
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? :\
-
Jul 14th, 2005, 03:49 AM
#7
Fanatic Member
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());
-
Jul 14th, 2005, 01:33 PM
#8
Thread Starter
New Member
Re: J#.NET - XML -> ListBox
Thanks very much
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|