Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My project has the Main Form with a listbox and a menu item that calls up another form with a listbox. I wanted to be able to select an item in the second listbox and by double clicking add it to the listbox on the main form.

I can't get this to work and I wondered if it was a "Modal" thing?
Posted

1 solution

Try This

Private Sub Listbox1_DoubleClick(Byval sender as Object, Byval e as system.eventargs) Handles Listbox1.DoubleClick
'Check for selected item
If Not listbox1.SelectedItem = Nothing Then
'add it

form1.listbox2.items.add(listbox1.selecteditem)
Else

'if user did not select item, notify them
MsgBox("Please double click an item from the list.", MsgBoxStyle.OkOnly,"Please Select An Item")
Return
End If

End Sub


Parameters
listbox1 = the list box on the second form
listbox2 = the list box on your main form
form1 = the second form

Good Luck in your programming :-)
 
Share this answer
 
Comments
Sandeep Mewara 19-Jul-10 2:32am    
Comment from OP: Thanks for that, and your good wishes.

But when I try that I get a message from VB something like:
"listbox2 is not a member of form1"

My original code based on the Parameters you mention is:

mainform.listbox2.items.add(listbox1.selecteditem)
and that's the code that's not working.
Paul Bayley 19-Jul-10 3:53am    
My sincere apologies. I failed to cover all the possibilities as to why my code wasn't working (I never learn !!).
The problem actually originated in that the listbox on the main form was one of a number, one on each tab page of a tab control. The "active tab" string returned I presumed to be "0" for page one, "1" for page two etc. this I have now found to be "" for page 1, "1" for page 2 etc.

The Select Case "active tab string"
Case "0"
drew a blank !!!

Now Case "" works fine............once again my apologies for wasting your time.
Paul

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900