Results 1 to 4 of 4

Thread: Right-clicking on a ListView component

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2002
    Posts
    61

    Right-clicking on a ListView component

    I have created a ListView box that displays some text-based items.

    How would I do it so when someone right-clicks on an item, it manefests a pop-up menu with options?

    Thanks

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Right-clicking on a ListView component

    Quote Originally Posted by Dr.Rock
    I have created a ListView box that displays some text-based items.

    How would I do it so when someone right-clicks on an item, it manefests a pop-up menu with options?

    Thanks
    Create a menu using the standard Menu Editor.

    Set the top level menu's visible property to False.

    For the sake of an example, I will use mnuFile as the top level menu.
    VB Code:
    1. Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    2. If Button = vbRightButton Then
    3.    PopUpMenu mnuFile
    4. End If
    5. End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2002
    Posts
    61

    Re: Right-clicking on a ListView component

    Thanks for that. It works so far with my app.

    But the menu item I right-click on does not highlight. Is there a way that the menu item highlights when I right-click, before the pop-up menu comes? The popup menu is to refer to the item I select via right-click.

    Thanks.
    Last edited by Dr.Rock; Aug 11th, 2005 at 09:34 AM.

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Right-clicking on a ListView component

    Use the HitTest method to determine which Item the mouse is clicked upon.

    Note that the View and FullRowSelect property values affect how the HitTest method determines if an Item is at the X, Y coordinate.

    VB Code:
    1. Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    2.     Dim oItem As ListItem
    3.     If Button = vbRightButton Then
    4.         Set oItem = ListView1.HitTest(x, y)
    5.         If Not oItem Is Nothing Then
    6.             oItem.Selected = True
    7.             popupmenu mnuFile
    8.         End If
    9.     End If
    10. End Sub

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