473,396 Members | 2,018 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,396 software developers and data experts.

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 1290
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.controls
if TypeOf ctr is CheckBox Then
'only the checkbox and the radiobutton have a checkbox
Directcast(ctr, Checkbox.CheckState = CheckStateChecked
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 SetAllCheckStateTrue(ByVal parentCtr As Control)
For Each ctr As Control In parentCtr.Controls
If TypeOf ctr Is CheckBox Then
DirectCast(ctr, CheckBox).CheckState = CheckState.Checked
End If
SetAllCheckStateTrue(ctr)
Next
End Sub
///

I hope this helps,

Cor

"Robert Boudra" <rb*****@comcast.net> schreef in bericht
news:eS**************@TK2MSFTNGP11.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*****@comcast.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=controlbynameindex&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(sender, 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**************@TK2MSFTNGP09.phx.gbl...
"Robert Boudra" <rb*****@comcast.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=controlbynameindex&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(sender, 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
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. ...
3
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...
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: 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...
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...
2
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...
0
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,...

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.