473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 6377
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RBohannon | last post by:
Is it possible to create a control array on an unbound form? I would like to be able to loop through a series of unbound text boxes. Thanks.
13
by: Bernie | last post by:
Sorry, but this ia another whine about VB.Net's lack of Control Arrays. I am new to VB.Net and I'm building an application that uses variable number of Label controls that are created at run...
2
by: Merlin | last post by:
Hi I have a control that allows embeddable editors, so for example I can set a property of controlsEmbeddableEditor =me.TextBox1 on my form, no problem here - what I want to do is the same thing...
3
by: B-Dog | last post by:
I'm capturing the checked radio button to XML file using the name of the radio button. I want to read my xml file to find which button was checked on close and the check the appropriate button...
3
by: Robert | last post by:
How can I declare in VB .NET an array of labels for example and afterwards using a FOR structure load every component of the array? I've used this code but it doesn't work: dim x(10) as label...
20
by: samean | last post by:
Hello, Could you explain me,In VB6 using control array,and how about VB.net. Thanks
8
by: Greg | last post by:
In VB6 I made heavy use of control arrays I see they have been 'deprecated' in vb.Net, with a questionable explanation that they are no longer necessary which just addresses the event issue!...
9
by: Michael D. Ober | last post by:
In VB 6, you can create control arrays for your option groups and scan with the following code dim opt as OptionButton for each opt in OptionGroup ' Do something next opt I know VB 2005...
4
by: Arne Beruldsen | last post by:
I'm a recent convert to VB.net from VB6...and I can't believe they don't support control arrays. I have an app that uses a ton of Control Arrays...mostly labels and text boxes. I need some...
13
by: Just_a_fan | last post by:
I am adding a bunch of controls with the code below. Problem 1: When program flow passes to "UpperChanged" when I click it, the control name is undefined. When I enter: If udUpperLim1.Value 1...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.