How do I find an item by value in an combobox in C#?

Duy Khanh picture Duy Khanh · Apr 15, 2012 · Viewed 92.4k times · Source

In C#, I have variable, a, of type string.

How do I find item by value of a in combobox (I want find item with value no display text of combobox).

Answer

st mnmn picture st mnmn · Apr 15, 2012

You can find it by using the following code.

int index = comboBox1.Items.IndexOf(a);

To get the item itself, write:

comboBox1.Items[index];