How to loop through a combox values list and select one of them

17,507

Solution 1

To cycle through combobox values, you can use the Items property. If combobox values are strings, the VB code would look like this:

For each item As String in myComboBox.Items
  'Do something
Next

To select a value, you can use the SelectedItem property:

myComboBox.SelectedItem = "SomeValueInComboBox"

Solution 2

foreach (var item in comboBox1.Items)
    Console.WriteLine(item.ToString());
Share:
17,507
stighy
Author by

stighy

Updated on June 14, 2022

Comments

  • stighy
    stighy almost 2 years

    How do I cycle through a ComboBox Values list so I can check each value and select one of them efficiently?

    Examples in C# or VB.Net welcome.

  • dmportella
    dmportella about 12 years
    Make sure to break out of the loop once you have selected the value that you want. (no point looping through data you don't need)