Solved

right double click a listbox

Posted on 2000-03-22
11
257 Views
Last Modified: 2010-08-05
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...
0
Comment
Question by:DvlpQst
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 27

Expert Comment

by:Ark
ID: 2647499
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
 
LVL 9

Expert Comment

by:Ruchi
ID: 2647850
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
 
LVL 27

Expert Comment

by:Ark
ID: 2647899
Hi
DblClick event doesn't fire if you use right button
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2647922
Ark: You are right. I just posted this by using my thought. Thanks for correcting...
0
 
LVL 27

Expert Comment

by:Ark
ID: 2647973
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Expert Comment

by:caraf_g
ID: 2648466
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
 
LVL 27

Accepted Solution

by:
Ark earned 40 total points
ID: 2648486
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
 
LVL 10

Expert Comment

by:caraf_g
ID: 2648544
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
 

Author Comment

by:DvlpQst
ID: 2648626
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
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2648642
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
 
LVL 10

Expert Comment

by:caraf_g
ID: 2648651
"right double click for list box 3 which is on the right side of the screen...."

Nooooooooooooooooooo <g>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now