-
Is it possible to select an entry in a listbox with the right button? I need to generate a pop-up menu when the right button is clicked, but if the entry of the listbox isn't selected with the right button, the menu is useless. Is there anyway the right button can select a listbox entry??
Thank you for your time,
Daniel K
-
no right click
to my knowlede no...but you could create a popup menu
and have it pop up on single click or double click.
-
Here is some simple code that should do the trick. I needed the same thing for a program i was writing so this is what i came up with. This code will click the left button first then bring up the popup menu. Email me and let me know if this works. [email protected]
do the following to set this up, and you should be able to modify to fit your neesds.
CREATE a FORM called FORM1
CREATE A MENU ITEM CALLED RIGHTCLK AND NAME IT RIGHTCLK
CREATE A SUBITEM CALLED Remove and name it remove
CREATE A LIST BOX NAMED LIST1
-=Create a module and paste the following code into it.=-
Declare Sub mouse_event Lib "user32" (ByVal dwflags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cbuttons As Long, ByVal dwextrainfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
-=On the form paste the following code into it.=-
Private Sub Form_Load()
RIGHTCLK.Visible = False ' <-- hides the menu
List1.AddItem "Richard"
List1.AddItem "Kristin"
End Sub
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then <-- if right mouse button is clicked
Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, ex) <-- clicks left button down
Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, ex)<-- clicks left button up
DoEvents
Form1.PopupMenu Form1.RIGHTCLK, 1
End If
End Sub
Private Sub REMOVE_Click()
'code goes here for the RIGHT menu click
ans = MsgBox("Remove " & List1.List(List1.ListIndex), vbYesNo + vbInformation, "Confirm")
End Sub
-
great idea
Works like a charm..great code...only one small drawback..it works the same as my suggestion because your code removes the possibility of using left click to select the item for other purposes.
I see you write script...
you forgot a few rem marks '
and used <...
the mouse down event with corrected rems(') is:
If Button = 2 Then '<-- if right mouse button is clicked
Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, ex) '<-- clicks left button down
Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, ex) '<-- clicks left button up
DoEvents
Form1.PopupMenu Form1.rightclk, 1
End If
[Edited by HeSaidJoe on 06-11-2000 at 09:15 PM]