Results 1 to 4 of 4

Thread: [RESOLVED] Help referencing a control as a string to get around no control arrays

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    63

    Resolved [RESOLVED] Help referencing a control as a string to get around no control arrays

    Hello,

    I am trying to get around the lack of control arrays. I have 4 list boxes that I am trying to reference and add items to. VB6 had a cool controls function like the following.

    Controls("List" & 1).AddItem ("Test")

    I can't for the life of me figure this out in VB 2005.

    Any help would greatly be appreciated.
    Last edited by Mythos44; Nov 1st, 2007 at 03:38 PM. Reason: [RESOLVED]

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Help referencing a control as a string to get around no control arrays

    Control arrays exist in .Net, you just dont create them in the same way as in VB6. Try a search.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    499

    Re: Help referencing a control as a string to get around no control arrays

    Control arrays are just set a different way.
    Code:
    Private LB() As ListBox
    
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            LB = New ListBox() {Me.ListBox1, Me.ListBox2, Me.ListBox3, Me.ListBox4}
        End Sub
    
    
    For i As Integer = 0 To LB.Length - 1
                LB(i).Items.Add(i.ToString)
            Next

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    63

    Re: [RESOLVED] Help referencing a control as a string to get around no control arrays

    Thank you so much that worked Awesome. It is greatly appreciated.

    Mythos

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width