right double click a listbox

Experts,

Is there a way to catch the right double click event of a list box.  The listbox double click event works great for a left double click, but nothing happens when a right double click on the list box.....How can the right double click event get called with VB?  Thanks...
DvlpQstAsked:
Who is Participating?
 
ArkConnect With a Mentor Commented:
caraf_q,
I've already said to DvlpQst, that windows itself hasn't Right_DblClick Event, but may be all other mouse events are already in use in his/her listbox. Next event may be triple_click :-)
Cheers
0
 
ArkCommented:
Hi
Windows itself hasn't right dblclick event. May be Right_Click will be enough? If not, you have to specify delay and use timer
Cheers
0
 
RuchiCommented:
Try put something like this...

list1_DblClick()
if Button = vbRightButton Then
your code....
Else
.....
End If

You double-click the right mouse button...

Does it make sense to you?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ArkCommented:
Hi
DblClick event doesn't fire if you use right button
0
 
RuchiCommented:
Ark: You are right. I just posted this by using my thought. Thanks for correcting...
0
 
ArkCommented:
Hi
Here is a code:
Private Type POINTAPI
   X As Long
   Y As Long
End Type

Private Declare Function LBItemFromPt Lib "comctl32.dll" (ByVal hwnd As Long, ByVal ptx As Long, ByVal pty As Long, ByVal bAutoScroll As Long) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Dim curritem As Long

Private Sub Form_Load()
  Dim DblClickInterval As Single
  DblClickInterval = 0.5 'sec
  Timer1.Enabled = False
  Timer1.Interval = 1000 * DblClickInterval
  For i = 1 To 30
     List1.AddItem "Item" & CStr(i)
  Next i
End Sub

Private Sub List1_RightDblClick()
   MsgBox "You right doubleclick Item " & List1.List(curritem)
End Sub

Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   If Button = vbRightButton Then
      Dim pt As POINTAPI
      Dim tempItem As Long
      pt.X = X \ Screen.TwipsPerPixelX
      pt.Y = Y \ Screen.TwipsPerPixelY
      Call ClientToScreen(List1.hwnd, pt)
      tempItem = LBItemFromPt(List1.hwnd, pt.X, pt.Y, False)
      If tempItem > -1 Then List1.Selected(tempItem) = True
   End If
End Sub

Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
   If Button = vbRightButton Then
      Dim pt As POINTAPI
      Dim tempItem As Long
      pt.X = X \ Screen.TwipsPerPixelX
      pt.Y = Y \ Screen.TwipsPerPixelY
      Call ClientToScreen(List1.hwnd, pt)
      tempItem = LBItemFromPt(List1.hwnd, pt.X, pt.Y, False)
      If curritem = tempItem Then
         Timer1.Enabled = False
         List1_RightDblClick
      Else
         Timer1.Enabled = True
         curritem = tempItem
      End If
   End If
End Sub

Private Sub Timer1_Timer()
   curritem = -2
End Sub
0
 
caraf_gCommented:
Forget any of the above solutions, no matter how brilliantly they may be implemented.

Right-double-click is not standard windows behaviour.

Don't do it.

OK. Now, what exactly are you trying to achieve. If you explain that to us, perhaps we could suggest a way to resolve your problem within Windows standards.
0
 
caraf_gCommented:
I'm going to make a really facetious remark now for which I will apologise in advance, but...

if you need that many different click events your design is wrong. There are many ways to skin a cat, and there are ways to avoid this problem.

I'll need to know what DvlpQst needs all these different click events for. Once I know that I'll put on my lateral thinking cap and I'll come up with a solution that avoids non-standard behaviour.
0
 
DvlpQstAuthor Commented:
Thank you,

I didn't see right double click as an event, and thought it was standard...there is a left double click and maybe a right double click....

There are 3 list boxes and 2 list boxes are started from the first list box....a user moves an item to the 2 and 3 list boxes using drop and drag or by left double click for list box 2, and I thought, right double click for list box 3 which is on the right side of the screen....

I'll try to get a right double click working...Thanks
0
 
VbmasterCommented:
Add this to your form and you will get a 'doubleclick event'...

  Private Declare Function GetDoubleClickTime Lib "user32" () As Long

  Function TimerDiff(TimerStart As Single, TimerEnd As Single) As Single

    If (TimerEnd < TimerStart) Then
      'Assume across midnight
      TimerDiff = TimerEnd + (86400 - TimerStart)
    Else
      'Normal timer interval
      TimerDiff = TimerEnd - TimerStart
    End If
 
  End Function

  Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Static TimerLast As Single
 
    If (TimerLast = 0) Then
      'Start new doubleclick event
      TimerLast = Timer
    ElseIf (TimerDiff(TimerLast, Timer) * 1000 > GetDoubleClickTime()) Then
      'The time interval was too big to be a doubleclick
      TimerLast = Timer
    Else
      'Doubleclick event show nice message to user
      MsgBox "Strange doubleclick event raised"
      TimerLast = 0
    End If
 
  End Sub
0
 
caraf_gCommented:
"right double click for list box 3 which is on the right side of the screen...."

Nooooooooooooooooooo <g>
0
All Courses

From novice to tech pro — start learning today.