15

I have a combobox, and I would like to search through every element in it.

How can I do this? (also the number of items is not the same everytime, but this is not so important).

I am using c# windows form application.

4

2 回答 2

35

you can do this

for (int i = 0; i < myComboBox.Items.Count; i++)
{
     string value = myComboBox.GetItemText(myComboBox.Items[i]); 
}
于 2013-08-26T11:38:45.237 回答
9

Use a foreach loop. It will iterate all your items of ComboBox regardless of their count, e.g.

foreach(var item in myComboBox.Items)
{
// do something with your item
}
于 2013-08-26T11:39:52.540 回答