binding listbox to xml element

Hi,

I have a listbox control. How can I bind the listbox to an element of xml 
I want to bind the list panel control to the "id" element in the xml.


<Accounts>
    <Account>
        <id>Test</id>
        <Password>PwdTest</Password>
        <Previliges>
            <Options>0</Options>
            <Users>1</Users>
        </Previliges>
    </Account>
    <Account>
        <id>Test</id>
        <Password>PwdTest</Password>
        <Previliges>
            <Controls>0</Controls>
            <Options>0</Options>
        </Previliges>
    </Account>
</Accounts>


Answer this question

binding listbox to xml element

  • LHammer

    The easiest way would be to load the file into a DataSet and use it as the data source for the ListBox.DataSet ds = new DataSet();
    ds.ReadXml("data.xml");
    listBox1.DataSource = ds.Tables[0];
    listBox1.DisplayMember = "id";This might not me the most resource-friendly technique if the XML file is very large because the whole file is kept in memory in the form of a DataSet, which isn't exactly petite itself.

  • binding listbox to xml element