Loop Control array

  • Thread starter Thread starter samean
  • Start date Start date
S

samean

Hello,
Could you explain me,In VB6 using control array,and how
about VB.net.

Thanks
 
Hi Samean,

A lot of methods, so tell what you want to archieve because a general one
does probably not help you.

Cor
 
Could you explain me,In VB6 using control array,and how
about VB.net.

For VB6, ask in microsoft.public.vb.general.discussion, and for .NET, they
no longer exist.
 
and for .NET, they no longer exist.

Are you sure of that, I though exactly the oposite.

Cor
 
Are you sure of that, I though exactly the oposite.

Control arrays no longer exist in .NET, I know that for sure. However, I may
have slightly misinterpreted the poster's question. I read "How do you loop
through a control array in VB6 and .NET?" The question may actually have
been, "How do I loop through controls? Please show me using a control array
in VB6 and however it's done in .NET."
 
Hi Jeff,

All controls exist as arrays now (or reference in a control.collections
however that is for me the same, it is uses Ilist).

That means that there are as I wrote more possibilities, I give here 3
however it is of course endless.

One which looks I thought the most as the one that was in VB6.
\\\needs two buttons and a label on a form
Dim btnArea As Button() = New Button() {Button1, Button2}
For Each btn As Button In btnArea
AddHandler btn.MouseLeave, AddressOf Button_MouseLeave
Next
Private Sub Button_MouseEnter(ByVal sender As Object, _
ByVal e As System.EventArgs)
Me.Label1.Text = DirectCast(sender, Button).Name
End Sub
///
The most standard one
\\\
For each btn as button in me.controls
if typeof btn Is Button then
bla bla bla
end if
next
///
And the one I like the most.
\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doset(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
AddHandler ctr.LostFocus, AddressOf meLostFocus
AddHandler ctr.GotFocus, AddressOf meGotFocus
doSet(ctr)
Next
End Sub
Private Sub meLostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
last = DirectCast(sender, Control).Name
End Sub
Private Sub meGotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Control).Text = last
End Sub
///

I hope this gives some idea of going throug a control array?

Cor
 
All controls exist as arrays now (or reference in a control.collections
however that is for me the same, it is uses Ilist).

Well, it is NOT the same as what VB6 called a "control array," and I think
it's confusing to people who have used both to state that there are "control
arrays" in .NET. Most VB6'ers would assume that means that you can have
controls on a form named, for example:

txtData(0)
txtData(1)
txtData(2)
etc.
 
Jeff,

Did I say it is the same, you said there exist no array of controls in
VBNet.

However that was not the question of the OP. (As you stated already)

I know that it is not what was called in VB6 a control array, luckily not.

However there is the control.collection in every control which implements
from the same class as array does.

:-)

Cor
 
Did I say it is the same, you said there exist no array of controls in
VBNet.

No, I didn't say "array of controls"; in fact I didn't use the term at all,
at first. The original poster said "control array" and I said they don't
exist in .NET:

--------------------------------------------
Could you explain me,In VB6 using control array,and how
about VB.net.

For VB6, ask in microsoft.public.vb.general.discussion, and for .NET, they
no longer exist.
--------------------------------------------
 
No, I didn't say "array of controls"; in fact I didn't use the term at all,
at first. The original poster said "control array" and I said they don't
exist in .NET:

Yes and it that you are wrong.

Cor
 
Yes and it that you are wrong.

From MSDN (specifically
http://msdn.microsoft.com/library/d.../vbconcontrolarraychangesinvisualbasicnet.asp):

--------------
In Visual Basic 6.0, control arrays could be used to specify a group of
controls that shared a set of events. The controls had to be of the same
type, and they had to have the same name.

In Visual Basic .NET, control arrays are no longer supported. Changes to the
event model make control arrays unnecessary. Just as control arrays in
Visual Basic 6.0 could share events, the event model in Visual Basic .NET
allows any event handler to handle events from multiple controls. In effect,
this allows you to create groups of controls of disparate types that share
the same events.
--------------

Plain and simple, I don't care if you like to use the terms "array of
controls" and "control arrays" interchangably; the fact is that as far as
Microsoft is concerned they mean different things. We're all professionals
here (for the most part; there are some beginners) and we should be using
correct terminology, especially those of us answering questions, which you
do a lot of (and that's a good thing!). We owe it to the people asking
questions to avoid giving (potentially) confusing advice.
 
Interesting discussion between you and Mr. Cor. Your last note is interesting in that one can allow the same event handler to handle events from multiple controls. Do you have a code snippet that does this? I don't understand how it's done.
 
Interesting discussion between you and Mr. Cor. Your last note is interesting
in that one can allow the same event handler to handle events from multiple
controls. Do you have a code snippet that does this? I don't understand how
it's done.

Sure, but I'm going to be lazy about it: look back in this group for a
thread titled "Handler question" from 2004-07-29 5:41PM (EDT) and read the
responses.
 
Dennis,

In this thread are two samples from it, use the last one it is recursive and
very handy.

Cor
 
Jeff,

This is not the first time in this newsgroup that you try to convert VB6 to
VBNet.

The VB6 type control array does luckily not exist in VBNet.

However that does not mean that VBNet has no arrays of controls. You see I
write arrays, because every control (from which the Form is one) has a
control.collection.

http://msdn.microsoft.com/library/d...stemwindowsformscontrolclasscontrolstopic.asp

The reason I take so much time in this thread is that I do not want that
people get the wrong advice and think that because you said "there is no
Control Array in VBNet" the cannot do the things they want to do.

You see seldom the regulars in this newsgroup tell people here in this group
that things cannot be done. And mostly they wait than a long time before
answering. A lot of those things are than even done by our appreciated
cleansweaper Peter Huang who sometimes than even finds a solution or take it
back to his backoffice.

Cor



Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top