The situation is like this, says:
I have textbox1 to textbox20 to show real-time reading, then textbox21 to textbox40 for other purpose. So textbox1-20 can be manage in group through:

For index As Integer = 1 To 20
            Form1.Controls("Textbox" & index).BackColor = SystemColors.Window
        Next

The problem is, after some time i feel i like to change the order or add/delete few textbox, then i need to change the control name one by one by entering the name by hands(says if i add a text box then its name will be textbox41, then then For loop wont work, Or I deicided to delete the textbox15, forloop wont work either, then i need to rename them manually.)

Question: If there a ways that create a control array in VB 2008 express edition? which can set the name of Textbox1-20 to ButtonGroup then refer to them by says Buttongroup(1) for textbox1? (which means set a group of control in one name)

I'm quite new in VB, sorry if i ask a silly question^^ Thanks a lot:)

The situation is like this, says:
I have textbox1 to textbox20 to show real-time reading, then textbox21 to textbox40 for other purpose. So textbox1-20 can be manage in group through:

For index As Integer = 1 To 20
            Form1.Controls("Textbox" & index).BackColor = SystemColors.Window
        Next

The problem is, after some time i feel i like to change the order or add/delete few textbox, then i need to change the control name one by one by entering the name by hands(says if i add a text box then its name will be textbox41, then then For loop wont work, Or I deicided to delete the textbox15, forloop wont work either, then i need to rename them manually.)

Question: If there a ways that create a control array in VB 2008 express edition? which can set the name of Textbox1-20 to ButtonGroup then refer to them by says Buttongroup(1) for textbox1? (which means set a group of control in one name)

I'm quite new in VB, sorry if i ask a silly question^^ Thanks a lot:)

You can use List<T> to create a collection of TextBoxes.

Dim tboxes As New List(Of TextBox)

        tboxes.Add(TextBox1)
        tboxes.Add(TextBox2)
        tboxes.Add(TextBox3)

        For Each t As TextBox In tboxes
            t.BackColor = Color.Cornsilk
        Next

You can remove an element from the list also.

tboxes.RemoveAt(1) ' Remove the TextBox2

        'You can access list element through indices

        For i As Integer = 0 To tboxes.Count - 1
            tboxes(i).Text = "Hello " & Now.ToString()
        Next

Coooooool!!Just exactly what Im looking for( ⊙o⊙ )
Many ThanksO(∩_∩)O谢谢

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.