How to programmatically select a ComboBox item or value?
Posted on 2006-05-23
I have a programmatically populated ComboBox control (System.Windows.Forms) where each item contains text and value.
I populated the comtrol using statement like this:
cbxControl.Items.Add(new ListItem("text", "value"));
Now I need to programmatically select an item from the ComboBox control (in response of some user's action like a button click) and have the ComboBox to display the newly selected item (to change its previous selection).
Somehow this statement does not work:
cbxControl.SelectedIndex = index // an index that I want to select.
The question is: How to select an item from this ComboBox control and display the new selection?