473,761 Members | 9,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replacement for VB6 control Arrays

I remember when VB.net came out that a couple of the seminars I went to
mentioned that Control Arrays were going away and that there was a new and
better way to execute the same code when an event occurs in one of a group
of similar controls. Unfortunately, that was several years ago, and I don't
remember how to do this. Can someone refresh my memory?

Bob
Nov 21 '05 #1
3 1313
Robert,

That depends what you want.
In VB6 there was added an extra array that did hold all controls in a form.
Even if it was a child of an other control.
In VBNet every control (from which the form is one) has a control collection
(array).

Which means that all controls on a form can have again controls in
acollection. Think for that just on a groupbox.

You can get all controls direct on a form just by

\\\
for each ctr as control in me.controls
ctr.text = "whatever"
'this goes because every control has a property text
next
///
The same for in a groupbox
\\\
for each ctr as control in groupbox1.contr ols
if TypeOf ctr is CheckBox Then
'only the checkbox and the radiobutton have a checkbox
Directcast(ctr, Checkbox.CheckS tate = CheckStateCheck ed
end if
next
///

If you want to do this for a complete form than you have to do a recursion
trick from which are more, this is the one I like (the shortest to write in
my opinion)
\\\
Private Sub SetAllCheckStat eTrue(ByVal parentCtr As Control)
For Each ctr As Control In parentCtr.Contr ols
If TypeOf ctr Is CheckBox Then
DirectCast(ctr, CheckBox).Check State = CheckState.Chec ked
End If
SetAllCheckStat eTrue(ctr)
Next
End Sub
///

I hope this helps,

Cor

"Robert Boudra" <rb*****@comcas t.net> schreef in bericht
news:eS******** ******@TK2MSFTN GP11.phx.gbl...
I remember when VB.net came out that a couple of the seminars I went to
mentioned that Control Arrays were going away and that there was a new and
better way to execute the same code when an event occurs in one of a group
of similar controls. Unfortunately, that was several years ago, and I
don't remember how to do this. Can someone refresh my memory?

Bob

Nov 21 '05 #2
"Robert Boudra" <rb*****@comcas t.net> schrieb:
I remember when VB.net came out that a couple of the seminars I went to
mentioned that Control Arrays were going away and that there was a new and
better way to execute the same code when an event occurs in one of a group
of similar controls.


Accessing controls by their names or indices
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbyna meindex&lang=en >

If you want to handle events of several controls in a single event handler,
you can extend the event handler's 'Handles' list:

\\\
Private Sub Button_Click(.. .) Handles Button1.Click, Button2.Click,
Button3.Click
Dim SourceControl As Button = DirectCast(send er, Button)
Select Case True
Case SourceControl Is Button1
...
Case SourceControl Is Button2
...
...
End Select
End Sub
///

If your controls are created dynamically at runtime, check out the
'AddHandler' and 'RemoveHandler' statements.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
Ah...that was it. Thanks,

Bob

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:uQ******** ******@TK2MSFTN GP09.phx.gbl...
"Robert Boudra" <rb*****@comcas t.net> schrieb:
I remember when VB.net came out that a couple of the seminars I went to
mentioned that Control Arrays were going away and that there was a new and
better way to execute the same code when an event occurs in one of a group
of similar controls.


Accessing controls by their names or indices
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbyna meindex&lang=en >

If you want to handle events of several controls in a single event
handler, you can extend the event handler's 'Handles' list:

\\\
Private Sub Button_Click(.. .) Handles Button1.Click, Button2.Click,
Button3.Click
Dim SourceControl As Button = DirectCast(send er, Button)
Select Case True
Case SourceControl Is Button1
...
Case SourceControl Is Button2
...
...
End Select
End Sub
///

If your controls are created dynamically at runtime, check out the
'AddHandler' and 'RemoveHandler' statements.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4388
by: Freejack | last post by:
Recently I've been spending some time googling around for ideas for an alloca() replacement that could function in a strict ANSI C environment. As we all know, alloca() is system/arch dependant. I'm thinking of trying to implement something like "local allocate", lallocat(), for temporary variables that should be automatically freed when they go out of scope(function or block). For simplicity sake, I'm considering something like this...
3
1405
by: chris | last post by:
Hallo, I am in need of a replacement for the Microsoft Visual Studio .NET. The reason is quiet simple. I develop forms which are used on different microsoft windows platform, and one microsoft windows platform spoils the other microsoft windows platform. For example: I have two projects, one for pc and one for pocket pc. I would like (or better I have to) share the
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
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
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?
2
1274
by: johni58 | last post by:
I have several VB6 applications that I am rewriting in VB2005 Express. I used invisible control arrays to place labels over snapshots on a thumbnail screen. Choosing one of the thumbs would open the enlarged version of that thumb from a file folder of jpgs. Unfortunately VB2005 no longer has a way to make a click event on a particular portion of a larger thumbnail screen. I just need an idea from anyone who has one. I thought of tracking cursor...
4
2626
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
1690
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
9988
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...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
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
6640
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
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3911
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
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.