How to fill 56 comboBox with loop or something

I have 56 comboBox in my program and I need to fill all of them with the same information. The fastes way that I found is creating a private function for fill the comboBox. And I put 56 times the same function.

But my question is... I can do a loop for fill this 56 comboBox?


Assuming this question is about Windows Forms. The best way to do it is probably to have the similar naming convention for all ComboBox controls you're willing to fill with the same data. Fill them with items within for-loop, adding different suffix to the control you want to find before adding data.

// Lets say you have 56 ComboBox controls with names like : cbMyComboBox_1, cbMyComboBox_2, ..., cbMyComboBox_56
for (int i = 1; i <= 56; i++)
    ComboBox comboBox = (ComboBox)this.Controls.Find
        (string.Format("cbMyComboBox_{0}", i), true)[0];

private void ComboBoxFill(ComboBox comboBox)
    // Fill that ComboBox with data here

Of course you can.

foreach (var c in Controls)
    if (c is ComboBox)
        ((ComboBox)c).Text = "I'm a combobox~";

Need Your Help

Switch statement automatically performing cases without meeting case requirements?

javascript switch-statement case

I made this switch statement and it begun to work until i began adding more code to it.. take a look:

need some help for a image slide show?

javascript jquery html css plugins

On my first day of work with html I built a navigation bar yesterday which looks pretty sweet to me ...take a look at it here

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.