1 Attachment(s)
Right Click ColumnHeader in ListView to PopupMenu
What would be the easiest way to make a popupmenu on a right click of the mouse, on the column header section?
The mouseup event on a listview doesn't happen if you click the header.
The column_Click event doesn't have a button variable.
Picture Below
http://www.vbforums.com/attachment.p...id=53091&stc=1
Re: Right Click ColumnHeader in ListView to PopupMenu
This is the code that I have so far. But I just need to know how to test for the right click.
VB Code:
Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos
As Long) As Long
Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, lpReserved As Any) As Long
Type Rect
Left As Integer
Top As Integer
Right As Integer
Bottom As Integer
End Type
Private Sub SearchListView_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 2 Then
Dim IX As Integer, IY As Integer
'hMenu and hSubMenu must be long to run on 32-bit
Dim hMenu As Long, hSubMenu As Long, R As Integer
Dim menRect As Rect
ScaleMode = 1 'twips
menRect.Left = 0
menRect.Top = 0
menRect.Right = Screen.Width / Screen.TwipsPerPixelX
menRect.Bottom = Screen.Height / Screen.TwipsPerPixelY
IX = (x + Form1.Left + mainsearchframe.Left + SearchTab.Left + SearchListView.Left + (Form1.Width - Form1.ScaleWidth)) \ Screen.TwipsPerPixelX
IY = (y + Form1.Top + mainsearchframe.Top + SearchTab.Top + SearchListView.Top + (Form1.Height - Form1.ScaleHeight)) \ Screen.TwipsPerPixelY
hMenu = GetMenu(rightclickdropdown.hwnd)
hSubMenu = GetSubMenu(hMenu, 1) ''whichmenu will select from left to right
R = TrackPopupMenu(hSubMenu, 2, IX, IY, 0, rightclickdropdown.hwnd, menRect)
End If
End Sub
Re: Right Click ColumnHeader in ListView to PopupMenu
Is there a windows API call to verify which button was pressed on a mouse? If not, am I going to have to sub-Class (not knowing much about what this is)
When I left click, I want it to alter the Ascending/Descending order of the items. But when I right click, I want it to show my popup window with the ability to select which columns you want to have displayed.
Re: Right Click ColumnHeader in ListView to PopupMenu
Take a look at Aaron Youngs code bank thread. It subclasses the listview and intercepts the header messages. I added to it in post 14 too.
http://vbforums.com/showthread.php?t=145805 (Post #1 and #14)
Re: Right Click ColumnHeader in ListView to PopupMenu
Thanks for that, I looked at it a bit, i'll mess around with it after work tomorrow, and respond, or make the thread Resolved accordingly. Thanks for the input, tired and going to sleep.