[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:
' Add the textboxes
fwyOutCheckBoxes.Add(Me.chkFwy1)
fwyOutCheckBoxes.Add(Me.chkFwy2)
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:
' Add the textboxes
For i As Integer = 1 To 9
' Something else probably goes here?
GIRInCheckBoxes.Add(somethingIDontknow, "Me.chkFwy" & i.ToString, somethingIDontknow)
' And here
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. :)
Re: [2005] Adding to a Generic List
This should work
vb Code:
For Each ctr As Control In Me.Controls
If ctr.GetType Is GetType(Label) Then
If ctr.Name.Contains("chkFwy") Then
fwyOutCheckBoxes.Add(ctr)
End If
End If
Next
Re: [2005] Adding to a Generic List
After casting ctr to the right control, that works! Thanks for getting me going. :thumb: