Control arrays

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

Guest

Hi

I need to know how to work with a control array in c#. I would
like to clear the contents of a textbox array after adding up the
values in the textboxes. This is really easy in VB6 - im sure it easy
in C# aswell - i just need the syntax.

Thanks in anticipation

Christopher
 
Christopher said:
I need to know how to work with a control array in c#. I would
like to clear the contents of a textbox array after adding up the
values in the textboxes. This is really easy in VB6 - im sure it easy
in C# aswell - i just need the syntax.

There's no specific control array semantics in C#. You just need to
create an array of controls, and then you can iterate through them
clearing them or whatever.
 
Christopher,

As Jon says you can create an array of controls. However, these controls do
not appear in the form designer, which may or may not be a problem for you.

If this is a problem, the I would suggest you add the controls using the
designer as normal, and then in addition add references to these controls
into an array once InitializeComponent() has been called.

It is a shame that there isnt a mechanism to do this in the form designer,
as per VB6 - it seems like a backward step.

Chris.
 
There was never any error for adding controls with the same name. You can
always write a generic post processing method to expose any repeating
named elements of similar types as arrays of controls. The perf is always
better doing the post InitializeComponent, or using a real array, but if you
plan on changing the number of elements by dynamically creating new
controls then maybe a growing list (ArrayList) isn't such a bad idea.

ControlAdded/Removed events round out your arsenal for applying a truly
bolt-on component and still having it work as a control array grouper.
 
Back
Top