-
Jan 25th, 2000, 01:41 AM
#1
Thread Starter
PowerPoster
-
Jan 25th, 2000, 02:46 AM
#2
New Member
here u go
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
Dim AnyItem As ListItem
'HitTest returns a node object under the cursor
Set AnyItem = ListView1.HitTest(X, Y)
If Not AnyItem Is Nothing Then
Set ListView1.DropHighlight = AnyItem
ListView1.DropHighlight.Selected = True
End If
End If
Set AnyItem = Nothing
End Sub
i tested it works with vb6, tell me if it dosent work with 5. Thanks to developers code book for the idea.....
-
Jan 25th, 2000, 03:01 AM
#3
You can use a couple of API calls to select a ListItem with the Right Mouse Button, try this:
Code:
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Const LB_ITEMFROMPOINT = &H1A9
Private Sub Form_Load()
Dim iIndex As Integer
For iIndex = 1 To 100
List1.AddItem "Item" & iIndex
Next
End Sub
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim tPOINT As POINTAPI
Dim iIndex As Long
If Button = vbRightButton Then
Call GetCursorPos(tPOINT)
Call ScreenToClient(List1.hWnd, tPOINT)
iIndex = SendMessage(List1.hWnd, LB_ITEMFROMPOINT, 0&, ByVal ((tPOINT.X And &HFF) Or (&H10000 * (tPOINT.Y And &HFF))))
If iIndex > -1 Then
iIndex = iIndex And &HFF
List1.Selected(iIndex) = True
End If
End If
End Sub
Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Do the Same as in the MouseDown Event
Call List1_MouseDown(Button, -1, X, Y)
End Sub
Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then PopupMenu mnuPopup, vbPopupMenuRightButton
End Sub
Private Sub mnuRemove_Click()
MsgBox "Remove List Item " & List1
End Sub
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com
-
Jan 25th, 2000, 12:40 PM
#4
Member
Hi folks.
When I rightclick on a listbox, I've got a menu popup. But what the menupopup displays depends on the selected item. How can I get the listbox to select the item like a leftclick before I do my menupopup stuff? As it is at the moment, the listbox doesn't select the rightclicked item at all.
Any ideas?
Thanks very much,
AndyC
------------------
* * * * * * * * * * * * * * * * * * * * * *
AndyC
London
email: andy.collyer@bigfoot.com
* * * * * * * * * * * * * * * * * * * * * *
-
Jan 25th, 2000, 12:52 PM
#5
New Member
I don't think there is a way, unless you could invert the mouse buttons when you are over the list and to programmaticaly call the popup menu. That way the user would have the illusion that he has done a left click. GOOD LUCK
-
Jan 25th, 2000, 05:25 PM
#6
Member
-
Jan 25th, 2000, 06:37 PM
#7
Member
Right, for those interested, here's some code to do the job...
Code:
Private Sub ListBox1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (Button = vbRightButton) Then
' ensure the correct row is selected
Dim Item2Select As Integer
Item2Select = GetSelectedItem(ListBox1, Y)
If Item2Select >= 0 Then
ListBox1.ListIndex = Item2Select
PopupMenu menuList, , , , menuListPing
End If
End If
End Sub
' and the actual function...
Private Function GetSelectedItem(ByVal LBpassed As ListBox, ByVal Ypos As Single) As Integer
Dim h As Integer
h = TextHeight("1234567890.")
GetSelectedItem = Int(Ypos / h) + LBpassed.TopIndex
If GetSelectedItem >= LBpassed.ListCount Then GetSelectedItem = -1
End Function
AndyC
------------------
* * * * * * * * * * * * * * * * * * * * * *
AndyC
London
email: andy.collyer@bigfoot.com
* * * * * * * * * * * * * * * * * * * * * *
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|