Results 1 to 5 of 5

Thread: Right Click ColumnHeader in ListView to PopupMenu

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Anchorage, Alaska
    Posts
    545

    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

    Attached Images Attached Images  
    Last edited by rack; Dec 12th, 2006 at 02:31 AM.
    Please RATE posts, click the RATE button to the left under the Users Name.

    Once your thread has been answered, Please use the Thread Tools and select RESOLVED so everyone knows your question has been answered.


    "As I look past the light, I see the world I wished tonight, never the less, sleep has come, and death shall soon follow..." © 1998 Jeremy J Swartwood

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Anchorage, Alaska
    Posts
    545

    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:
    1. Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
    2. Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos
    3. As Long) As Long
    4.  
    5. 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
    6.  
    7. Type Rect
    8.     Left As Integer
    9.     Top As Integer
    10.     Right As Integer
    11.     Bottom As Integer
    12. End Type
    13.  
    14.  
    15. Private Sub SearchListView_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    16. If Button = 2 Then
    17.     Dim IX  As Integer, IY As Integer
    18.     'hMenu and hSubMenu must be long to run on 32-bit
    19.     Dim hMenu As Long, hSubMenu As Long, R As Integer
    20.     Dim menRect As Rect
    21.  
    22.         ScaleMode = 1 'twips
    23.         menRect.Left = 0
    24.         menRect.Top = 0
    25.         menRect.Right = Screen.Width / Screen.TwipsPerPixelX
    26.         menRect.Bottom = Screen.Height / Screen.TwipsPerPixelY
    27.         IX = (x + Form1.Left + mainsearchframe.Left + SearchTab.Left + SearchListView.Left + (Form1.Width - Form1.ScaleWidth)) \ Screen.TwipsPerPixelX
    28.         IY = (y + Form1.Top + mainsearchframe.Top + SearchTab.Top + SearchListView.Top + (Form1.Height - Form1.ScaleHeight)) \ Screen.TwipsPerPixelY
    29.         hMenu = GetMenu(rightclickdropdown.hwnd)
    30.         hSubMenu = GetSubMenu(hMenu, 1) ''whichmenu will select from left to right
    31.         R = TrackPopupMenu(hSubMenu, 2, IX, IY, 0, rightclickdropdown.hwnd, menRect)
    32. End If
    33. End Sub
    Please RATE posts, click the RATE button to the left under the Users Name.

    Once your thread has been answered, Please use the Thread Tools and select RESOLVED so everyone knows your question has been answered.


    "As I look past the light, I see the world I wished tonight, never the less, sleep has come, and death shall soon follow..." © 1998 Jeremy J Swartwood

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Anchorage, Alaska
    Posts
    545

    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.
    Please RATE posts, click the RATE button to the left under the Users Name.

    Once your thread has been answered, Please use the Thread Tools and select RESOLVED so everyone knows your question has been answered.


    "As I look past the light, I see the world I wished tonight, never the less, sleep has come, and death shall soon follow..." © 1998 Jeremy J Swartwood

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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)
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Anchorage, Alaska
    Posts
    545

    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.
    Please RATE posts, click the RATE button to the left under the Users Name.

    Once your thread has been answered, Please use the Thread Tools and select RESOLVED so everyone knows your question has been answered.


    "As I look past the light, I see the world I wished tonight, never the less, sleep has come, and death shall soon follow..." © 1998 Jeremy J Swartwood

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width