|
-
May 12th, 2003, 05:56 AM
#1
Thread Starter
Junior Member
populating a combobox
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.
-
May 12th, 2003, 10:17 AM
#2
PowerPoster
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.
-
May 12th, 2003, 10:22 AM
#3
Thread Starter
Junior Member
it's a possibility. I will prove this implementation. Thank's
-
May 12th, 2003, 11:28 AM
#4
Sleep mode
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);
}
-
May 12th, 2003, 01:14 PM
#5
Frenzied Member
You can use databinding
Code:
DataSet ds = new DataSet();
ds.ReadXml("books.xml");
comboBox1.DataSource = ds.Tables["book"];
comboBox1.DisplayMember = "title";
comboBox1.ValueMember = "id";
Here is the XML file
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>
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
|