Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Adding to a Generic List

  1. #1

    Thread Starter
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Resolved [RESOLVED] [2005] Adding to a Generic List

    Hi all,

    I have a question about adding items to a Generic list.
    Example: I have 9 text boxes that I would like to add to a list. Typing all of them like:

    vb.net Code:
    1. ' Add the textboxes
    2.         fwyOutCheckBoxes.Add(Me.chkFwy1)
    3.         fwyOutCheckBoxes.Add(Me.chkFwy2)
    4.         fwyOutCheckBoxes.Add(Me.chkFwy3)

    is certainly no problem but I named them something like this specifically so I could loop through the names and add them to my list. However, I've failed in my search and many attempts to get this to work. I want to do something like this:

    vb.net Code:
    1. ' Add the textboxes
    2.         For i As Integer = 1 To 9
    3.             ' Something else probably goes here?
    4.             GIRInCheckBoxes.Add(somethingIDontknow, "Me.chkFwy" & i.ToString, somethingIDontknow)
    5.             ' And here
    6.         Next i

    I've typed so many things in that loop, I can't even remember them all. I'm sure I'm missing something pretty simple. Can someone point me to the right conversion, concept, something that will help?

    If you could, I'd rather you not just type out the answer.

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Adding to a Generic List

    This should work
    vb Code:
    1. For Each ctr As Control In Me.Controls
    2.             If ctr.GetType Is GetType(Label) Then
    3.                 If ctr.Name.Contains("chkFwy") Then
    4.                     fwyOutCheckBoxes.Add(ctr)
    5.                 End If
    6.             End If
    7.         Next

  3. #3

    Thread Starter
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] Adding to a Generic List

    After casting ctr to the right control, that works! Thanks for getting me going.

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