Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search through all items of a combobox in C#? [closed]

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.

like image 964
cabral_007 Avatar asked Aug 26 '13 11:08

cabral_007


People also ask

How do I find the index of a ComboBox?

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.

What is selected item in ComboBox?

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.


2 Answers

you can do this

for (int i = 0; i < myComboBox.Items.Count; i++)
{
     string value = myComboBox.GetItemText(myComboBox.Items[i]); 
}
like image 80
Ehsan Avatar answered Sep 21 '22 18:09

Ehsan


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
}
like image 30
insomnium_ Avatar answered Sep 21 '22 18:09

insomnium_