D
David C
I am trying to emulate with ComboBox, what I do with a Web DropDownList.
dropdownList.Items.Add(new ListItem("30", "30 days"));
dropdownList.Items.Add(new ListItem("60", "60 days"));
As you can see, 30 and 60 are values and "30 days" and "60 days" for displaying. Not populating from the database here. I just want those two items to be in the combo box. Very simple.
Cannot for the life of me figure out how to do this. ComboBox.Items is an ObjectCollection, and I have no idea how to emulate the above.
So I decided to create table like this and populate.
DataTable table = new Table();
table.Columns.Add("Value");
table.Columns.Add("Display");
//and create rows with what I want to populate
DataRow row = table.NewRow();
row["Value"] = 30;
row["Display"] = "30 days";
table.Rows.Add(row);
cmbBox.ValueMember = "Value";
cmbBox.DisplayMember = "Display";
cmbBox.DataSource = table;
Now that seems like a lot of code for something very simple.
And the strangest thing is, when cmbBox.DataSource = table executes, the SelectedIndexChanged event fires!
PS: I am still using .NET 1.x.
dropdownList.Items.Add(new ListItem("30", "30 days"));
dropdownList.Items.Add(new ListItem("60", "60 days"));
As you can see, 30 and 60 are values and "30 days" and "60 days" for displaying. Not populating from the database here. I just want those two items to be in the combo box. Very simple.
Cannot for the life of me figure out how to do this. ComboBox.Items is an ObjectCollection, and I have no idea how to emulate the above.
So I decided to create table like this and populate.
DataTable table = new Table();
table.Columns.Add("Value");
table.Columns.Add("Display");
//and create rows with what I want to populate
DataRow row = table.NewRow();
row["Value"] = 30;
row["Display"] = "30 days";
table.Rows.Add(row);
cmbBox.ValueMember = "Value";
cmbBox.DisplayMember = "Display";
cmbBox.DataSource = table;
Now that seems like a lot of code for something very simple.
And the strangest thing is, when cmbBox.DataSource = table executes, the SelectedIndexChanged event fires!
PS: I am still using .NET 1.x.