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());
Author by
stighy
Updated on June 14, 2022Comments
-
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 about 12 yearsMake 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)