473,756 Members | 6,106 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6405
Christopher <Ch*********@di scussions.micro soft.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.co m>
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 InitializeCompo nent() 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*********@di scussions.micro soft.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.co m>
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 InitializeCompo nent, 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*********@ty peYAHOOhere.com > wrote in message
news:9C******** *************** ***********@mic rosoft.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 InitializeCompo nent() 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*********@di scussions.micro soft.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.co m>
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
18606
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
1593
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 time. The number of label controls will vary between 50 and 200. I have created an array of labels and placed them on the form. It works great, BUT I have not been able to raise any events for these controls. I made a small demo with 9 labels...
2
1346
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 but from a string variable. i.e. I have 14 controls that have a name which is a permutation of 4 characters, my program selects which control to use by a 4 character name which matches a control name (it's a zillion times more complex than this...
3
3848
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 when for loads. How do I use a variable control name. This is what I'm trying to do below but of course it doesn't work, I'm rookie. Thanks Dim rbchecked as String
3
1391
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 for i=0 to 10 x(i)=new label
20
2388
by: samean | last post by:
Hello, Could you explain me,In VB6 using control array,and how about VB.net. Thanks
8
2323
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! Problem is I commonly associated several other controls with the same index inside the event handler - eg a Directory listbox, Label, Checkbox, Textbox Drivebox etc all associated with identical index. Now I see Control arrays belong to VB6...
9
5509
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 doesn't have control arrays, so my question is how do I do the equivalent in VB 2005?
4
2625
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 guidance on how to proceed...including any third party tools. Thanks
13
1689
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 Then I get an error that udUpperLim1 is "Not Defined" so I cannot get the value in the control.
0
9454
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9271
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9868
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9836
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7242
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6533
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5139
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3804
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.