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
 
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
 
Back
Top