I understand that control arrays are no longer supported in VB.NET; but how
can I handle the requirement for a control array. For instance if I have 30
listview controls that previously in VB6 I could alter their similar
attributes by the following means:
dim x as Long
x = 0
for x = 1 to 30
listview(x).backcolor = vbred
next x
Without a control array I would have to reference each controls properties
one at a time. The above example is changing just one attribute. My
situations that I am in are changing many attributes and at many different
times. This seems ridicules. How is this type of situation to be handled
in VB.net?
Thanks
John.
I posted a very similar question a week or so ago, but with Radio Buttons as
my object type. I agree 200% that what was handled pretty easily in VB 6 is
now more complicated in .NET. I can't say why controll arrays went away in
.NET (I'm sure there was a good reason) but they are gone.
Here's something that can point you in the right direction:
One of the benefits of control arrays was having a common event handler to
write code in just one place. You can still get that benefit by adding
creating a sub...end sub and add "handles objectName.event,
otherObjectName.event, etc." after the sub declaration like this. Consider
the code below wich works with 3 Radio Buttons and needs to figure out which
was clicked in order to work correctly:
Private Sub CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RadioButton1.CheckedChanged,
RadioButton2.CheckedChanged, RadioButton3.CheckedChanged
Dim rad As RadioButton
rad = CType(sender, RadioButton)
Select Case rad.Tag
Case "1"
Me.BackColor = Color.Green
Case "2"
Me.BackColor = Color.Blue
Case "3"
Me.BackColor = Color.Yellow
End Select
End Sub
One interesting new feature of .NET is that most objects have a "Tag"
property that you can place virtually ANY identifier information you want
into. In my case above, I set each of the radio buttons with a Tag value of
1, 2 or 3. Basically, I used the Tag property as you've used the Index
property in VB 6.
Hope this helps.
-Scott M.
"John W. Rugo" <jwr...@rcn.com> wrote in message
news:uGqDqKXiBHA.2260@tkmsftngp07...
create an additional array of the appropriate type (i. e. ListView) and
after instantiating the controls set the references in that array. Once you
have initialized that array, you can access your controls as if they belong
to a "ControlArray".
Something like this:
private MyListviews() as new ListView(20)
...
listviewXY = new ...
listviewUVW = new...
...
MyListviews(0) = listviewXY
MyListviews(1) = listviewUWV
...
for i=...
MyListviews(i)....
next
To share events, add the same event function to all controls instead of
creating one for each control. The "Sender" parameter is a reference to the
control that had fired the event.
Joachim
"Scott M." <s-...@snet.net> wrote in message
news:ekeahbyiBHA.1544@tkmsftngp02...
"Joachim Fuchs" <dr.f...@fuechse-online.de> wrote in message
news:#05dnnziBHA.2392@tkmsftngp02...
dim c as object
for each c in panel.controls
...
next
>.
>