E
E
Eugene Chefranov2020-05-09 21:17:26
C++ / C#
Eugene Chefranov, 2020-05-09 21:17:26

How to iterate through ComboBoxes?

Let's say I have a dozen ComboBoxes (startCompound1, startCompound2, startCompound3, etc.) and I need to go through and add elements to each.
I tried something like this but it didn't work

for (int i = 1; i <= 10; i++) {
 GroupBox1.Controls("startCompound" + i.ToString()).Items.Add(prop.name);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2020-05-09
@Chefranov

If you need to get a collection of some of the form elements, then you can do this.

var comboBoxes = Form1.Controls.OfType<ComboBox>();

foreach(var cb in comboBoxes)
{
// тут уже нужные вам действия
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question