Solved

right double click a listbox

Posted on 2000-03-22
11
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 28

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 28

Expert Comment

by:Ark
ID: 2647899
Hi
DblClick event doesn't fire if you use right button
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 28

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
 
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 28

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month4 days, 9 hours left to enroll

635 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