Creating Arrays of Controls in the Designer

Hi,
Before trying it, I thought I'd put this question to the group...
I have 3 combo box controls, and I'd like them in an array (maybe I'll add one or two later on, for example)
Now, the Windows Form Designer Code is 'untouchable', yet this would seem the only way I can achieve it.
eg.


private ComboBox combo1;
private ComboBox combo2;
private ComboBox combo3;


If I could change this in the Code Editor, I would probably just do:


private ComboBox[] combos =new ComboBox[3];
...
for (int x = 0; x < combos.Length; x++) {
combos[x] =new ComboBox();
}


But how can I do this if I'm not supposed to touch the Code Designer's Code?
[1367 byte] By [SpurryMoses] at [2007-12-16]
# 1
I understand that you are trying to create a control array rather than have three separate instances of combo boxes. You can't change the code designer's code because it will be overwritten when the designer accepts a modification. Control arrays were possible in older designers such as those in VB 6, but they appear to be difficult to impliment here.

I'm trying to understand what problem you are trying to solve that requires control arrays. The reasons for having a control array are few and far between anymore considering you can use the same event handler for multiple controls, or add controls at runtime by creating an instance of a control and add it to the Controls collection of the parent you want to add the control to.

If you have more information, I might be able to suggest another alternative.

TobinTitus at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
Thanks Tobin,
The 3 combo boxes I have, represent keywords in a text searching function. My class design has a 'KeywordManager' that uses them.
The KeywordManager often needs to iterate through the combo boxes and set the text to something, eg "". Or iterate through and take a 'snapshot' of all combo box text, to show/print a report of what was in them.
The clumsy parts of my code that I wanted to fix was mainly just passing the combo boxes to my KeywordManager class. It will get worse if I decide to change the number of keywords to 4, for example.
So, on the MainForm with the unavoidable non-array I have something like this:

KeywordManager.setUIControls (combo1, combo2, combo3);

Actually, my KeywordManager does have a ComboBox array, which I fill in, so it's just the passing that's the clumsy part...


public setUIControls(ComboBox combo1, ComboBox combo2, ComboBox combo3) {
combo[0]=combo1;
combo[1]=combo2;
combo[2]=combo3;
}


Wouldn't it be nicer if I could just pass in an array to my KeywordManager class ;-)
I've been reluctant to create them in code so far, because I do prefer to see them in the designer.
SpurryMoses at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3
You could add the participating comboboxes to an arraylist, for example, which you pass in to your manager. If you are looking for extensibility, though, consider packaging up your search controls into a user control.
durstin at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...