469,946 Members | 2,032 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,946 developers. It's quick & easy.

Control arrays

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
Nov 16 '05 #1
3 6186
Christopher <Ch*********@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
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.

"Jon Skeet [C# MVP]" wrote:
Christopher <Ch*********@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
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.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Chris Ballard" <wo*********@typeYAHOOhere.com> wrote in message
news:9C**********************************@microsof t.com...
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.

"Jon Skeet [C# MVP]" wrote:
Christopher <Ch*********@discussions.microsoft.com> wrote:
> 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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by RBohannon | last post: by
13 posts views Thread by Bernie | last post: by
2 posts views Thread by Merlin | last post: by
3 posts views Thread by B-Dog | last post: by
3 posts views Thread by Robert | last post: by
20 posts views Thread by samean | last post: by
4 posts views Thread by Arne Beruldsen | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.