Solved

right double click a listbox

Posted on 2000-03-22
11
256 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
Comment Utility
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
Comment Utility
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
Comment Utility
Hi
DblClick event doesn't fire if you use right button
0
 
LVL 9

Expert Comment

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

Expert Comment

by:Ark
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
"right double click for list box 3 which is on the right side of the screen...."

Nooooooooooooooooooo <g>
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

15 Experts available now in Live!

Get 1:1 Help Now