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.
However, if you want to get the index of selected items in the combobox widget, then you can use the get() method. The get() method returns an integer of the selected item known as the index of the item.
When you set the SelectedItem property to an object, the ComboBox attempts to make that object the currently selected one in the list. If the object is found in the list, it is displayed in the edit portion of the ComboBox and the SelectedIndex property is set to the corresponding index.
you can do this
for (int i = 0; i < myComboBox.Items.Count; i++)
{
string value = myComboBox.GetItemText(myComboBox.Items[i]);
}
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
}
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