c# combobox set selected item by item's text

2016/05/04 23:10 -

C# Combobox defined with name my_combobox
private System.Windows.Forms.ComboBox my_combobox;

Define string variable with the text of the combobox item that has to be selected. For example, if the combobox items have text values "item_a" "item_b" "item_c" ... and the item which text is "item_b" has to be selected

string select_this_item = "item_b";string item_text = "";  int i = 0;for (i = 0; i < my_combobox.Items.Count; i++) {    item_text = my_combobox.GetItemText(my_combobox.Items[i]);    if (item_text == select_this_item)    {       my_combobox.SelectedItem = (object)my_combobox.Items[i];       break;    }}