Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Items.add for Listbox in VB.Net

I am sure this is a simple question but the solution continues to elude this newbie. I want to add an item to a listbox on one form from another form. Items.add works fine from within the form, but I can't get it to work from another form or a module. help!
Steve
[280 byte] By [nemcruncher] at [2007-11-11 7:37:08]
# 1 Re: Items.add for Listbox in VB.Net
The simplest way is to change the ListBox declaration to Public. Then you can do:

FormName.ListBoxName.Items.Add

A cleaner solution, however, is to add a Public method to the form containing the ListBox:

Public Sub AddListBoxItem(Item As Object)
ListBoxName.Items.Add(Item)
End Sub

and call this method from the other form.
Phil Weber at 2007-11-11 21:48:52 >
# 2 Re: Items.add for Listbox in VB.Net
Yes! Option 2 worked. Thanks for getting me unstuck. Happy Programming in 2006!
nemcruncher at 2007-11-11 21:49:52 >