24-07-2012
string temp = "item1"; combobox1.items.add("item0"); combobox1.items.add("item1"); combobox1.items.add("item2");
I need to select “Item1” from the combo box. In other words, I need to select the index that matches the string in the “temp” variable and select that index.
Solution
int targetIndex = combobox1.FindString(temp); combobox1.selectedIndex = targetIndex;
Note:
The FindString looks for a substring. If you need to perform an exact comparison then use Combobox.FindStringExact() Both these functions has
overloads where you can pass an integer second parameter to tell if you want the search to start from a different index than the usual 0.
The Search is NOT case sensitive on either of these functions.
In earlier versions of .net framework these are called “FindString” and “FindStringExact”.
Menol
ILT