stighy
stighy

Reputation: 7170

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

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.

Upvotes: 7

Views: 19290

Answers (2)

Meta-Knight
Meta-Knight

Reputation: 17845

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"

Upvotes: 11

farooq
farooq

Reputation: 489

foreach (var item in comboBox1.Items)
    Console.WriteLine(item.ToString());

Upvotes: 1

Related Questions