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).
You can find it by using the following code.
int index = comboBox1.Items.IndexOf(a);
To get the item itself, write:
comboBox1.Items[index];
You should see a method on the combo box control for FindStringExact(), which will search the displaymember and return the index of that item if found. If not found will return -1.
//to select the item if found:
mycombobox.SelectedIndex = mycombobox.FindStringExact("Combo");
//to test if the item exists:
int i = mycombobox.FindStringExact("Combo");
if(i >= 0)
{
//exists
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With