Results 1 to 8 of 8

Thread: [RESOLVED] J#.NET - XML -> ListBox

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    6

    Resolved [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:
    1. DataSet dsItems = new DataSet("DataGrid");
    2.         String filePath = "Items.xml";
    3.         dsItems.ReadXml(filePath);
    4.         dataGrid1.set_DataSource(dsItems);
    5.         dataGrid1.set_DataMember("item");
    6.         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.

  2. #2
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    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");

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    6

    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.

  4. #4
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    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.

  5. #5
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: J#.NET - XML -> ListBox

    yeah I don't understand too.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    6

    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? :\

  7. #7
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    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());

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    6

    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
  •  



Click Here to Expand Forum to Full Width