Link to home
Start Free TrialLog in
Avatar of f_asmaa
f_asmaa

asked on

Array of control

I used to use array of controls in VB6 such as image control to share the same code between them and use index of the array to differentiate between them. Can I do the same in VB.NET?
ASKER CERTIFIED SOLUTION
Avatar of iboutchkine
iboutchkine

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RonaldBiemans
RonaldBiemans

control arrays aren't supported in vb.net

but you can get to them like

for each x as control in me.controls
              If x.GetType Is GetType(TextBox) Then
                CType(x, TextBox).Text = "test"
            End If
next

And if you want to use the same event for several controls

you can do something like this


    Private Sub txt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textbox1.TextChanged, textbox2.TextChanged
             ctype(sender,textbox).text += "ok"
    End Sub

or you can create your own array

dim mytextboxes(10) as textbox

mytextboxes(0) = textbox1
mytextboxes(1) = textbox2
etc..