Control array

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Sorry if this is an oft-posted question, but what is the C# equivalent of having a control array in VB6?
I know multiple controls can share the same event unlike VB6 ... if I want to enumerate over some radio buttons, say... do I just have to add them to a collection via code?
 
Hi,

I'm not sure if I understood your question. Here is a try: Each Form derived
class has a Controls collection. So if you have a form with a couple of
controls on it you could enumerate them like this:

foreach (Control c in this.Controls) {
c.Enabled = false;
}

HTH,

Matthias
--
-----
fragmente einer flugbahn - http://emvoid.de



Beeeeeeeeeeeeves said:
Sorry if this is an oft-posted question, but what is the C# equivalent of having a control array in VB6?
I know multiple controls can share the same event unlike VB6 ... if I want
to enumerate over some radio buttons, say... do I just have to add them to a
collection via code?
 
I know it does.
It doesn't have control arrays like VB6 though?


C# doesn't, nor does VB.NET I believe


Yes. Or go through their parent control's Controls collection as Matthias
said.
 
You could either add one in code as you say or if you particualry wanted to
get the designer to do the work add them into a GroupBox on the form. Then
you could have:

foreach(Control control in this.groupBox.Controls)
{

MessageBox.Show(control.Name);

}
 
Back
Top