I must to fill a combobox. My data source is an xml file. Wich is the better system to populate the combobox? I can do it with the traditional AddItem method, but I don't know if there is a better manner to do it. Thank you.
Printable View
I must to fill a combobox. My data source is an xml file. Wich is the better system to populate the combobox? I can do it with the traditional AddItem method, but I don't know if there is a better manner to do it. Thank you.
I am not very good with XML yet, but you could put that xml into a dataset, then databind the dataset to the combobox. You may be able to databind to the xml file, but I wouldn't know how.
it's a possibility. I will prove this implementation. Thank's
for example you can do something like this :
Load all tables in an XML File to dataset , loop through it , add table names to combobox .
Code:System.Data.DataSet ds=new DataSet();
ds.ReadXml("data.xml");
for(int i = 0; i < ds.Tables.Count - 1; i++)
{
this.comboBox1.Items.Add(ds.Tables[i].TableName);
}
You can use databinding
Here is the XML fileCode:DataSet ds = new DataSet();
ds.ReadXml("books.xml");
comboBox1.DataSource = ds.Tables["book"];
comboBox1.DisplayMember = "title";
comboBox1.ValueMember = "id";
PHP Code:<bookcollection>
<book>
<title>Vb.NET for Dummies</title>
<id>12236</id>
</book>
<book>
<title>C# For Dummies</title>
<id>32163</id>
</book>
<book>
<title>.NET Framework</title>
<id>52632</id>
</book>
</bookcollection>