Question dynamic controls in a form

mtnlvy

New member
Joined
Jun 6, 2011
Messages
3
Programming Experience
3-5
i have a form with many dynamic controls. i want to add an item to a listbox ( by the way, to find this listbox i'm using 'tag'. if someone have any other idea i'll be hope to hear but that's not the problem) in order to do so i use this code:
For Each ctl As Control In Me.Controls
If TypeOf ctl Is ListBox Then
ctl.items.add("i want to add this line")
' error massege
End If
Next
and items is not recognized and this eror massage apear:
'items' is not a member of 'System.Windows.Forms.Control'.
i use vb.net 2010
thank you very much
 

Joshdbr

Well-known member
Joined
Apr 7, 2011
Messages
211
Location
Montana, USA
Programming Experience
5-10
Try this instead:

For Each ctl As Control In Me.Controls
    If TypeOf ctl Is ListBox Then
        Dim lst As ListBox = ctl
        lst.Items.Add("i want to add this line")
        'error massege
    End If
Next
 
Top Bottom