Click to See Complete Forum and Search --> : Items.add for Listbox in VB.Net


nemcruncher
12-30-2005, 04:08 PM
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

Phil Weber
12-30-2005, 05:33 PM
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.

nemcruncher
01-01-2006, 08:16 AM
Yes! Option 2 worked. Thanks for getting me unstuck. Happy Programming in 2006!