Quote:
Originally Posted by sde
Geoff Alexander, aka PUN1SH3R, has contributed a VB.NET article demonstrating how to mimick a control array since MS has decided to take that out of VB.NET.
You can check out the article here.
|
This code works GREAT. I modified it to work in a group box with an array of pictureboxes.
I have been looking all over the web for something simple to do this and either they say it can't be done or you get some convoluted code. This is a nice simple way that I can't believe no one else has posted.
There does need to be 1 minor change - in the 2nd FOR Next loop, it should be Controls.Count - 1 (Count is number of controls, but array starts at zero)
My modified code
Code:
For x As Integer = 7 To 1 Step -1
For c As Integer = 0 To gbFanny.Controls.Count - 1
If TypeOf (gbFanny.Controls(c)) Is PictureBox Then
Dim pbname As String = "pbFanny" & x.ToString
If gbFanny.Controls.Item(c).Name = pbname Then
Dim pb As PictureBox = gbFanny.Controls(c)
pb.Image = arCards(x)
'Exit For
End If
End If
Next
Next
I think the previous poster misunderstood the point of the code. Of course you wouldn't do that for 4 simple text boxes but it's a great example of how to use control arrays - especially useful for Group Boxes that for some reason are unusually hard to manage.