Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding items to combobox
Message
From
03/10/2005 00:53:57
 
 
To
30/09/2005 16:16:08
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
01054999
Message ID:
01055413
Views:
22
Mike,

The easiest way to accomplish this, IMHO, is to create a quickie DataTable to use as the Combo's DataSource. Quick code off the top of my head:
DataTable dt = new DataTable();
dt.Columns.Add("MyDisplay", typeof(string));
dt.Columns.Add("MyValue", typeof(int));

DataRow row = dt.NewRow();
row["MyDisplay"] = "One";
row["MyValue"] = 1;
dt.Rows.Add(row);

row = dt.NewRow();
row["MyDisplay"] = "Two";
row["MyValue"] = 2;
dt.Rows.Add(row);

// etc.etc.

MyCombo.DataSource = dt;
MyCombo.DisplayMember = "MyDisplay";
MyCombo.ValueMember   = "MyValue";
~~Bonnie



>Sorry....
>
>What I want to do is manually add items to a combobox, where the SelectedItem is One, Two, Three, Four and the SelectedValue is 1,2,3,4. I am having problems figuring this one out...
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform