Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB8.0
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 18-Jul-10 19:25pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 Smile | :)
  Permalink  
Comments
Sandeep Mewara at 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 at 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)

  Print Answers RSS
0 DamithSL 265
1 CPallini 235
2 OriginalGriff 233
3 Maciej Los 195
4 George Jonsson 170
0 OriginalGriff 5,305
1 DamithSL 4,382
2 Maciej Los 3,760
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,901


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 19 Jul 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100