Results 1 to 3 of 3

Thread: Right click menu on a listview [RESOLVED]

  1. #1

    Thread Starter
    Lively Member spdracr's Avatar
    Join Date
    Oct 2003
    Location
    Kansas
    Posts
    115

    Right click menu on a listview [RESOLVED]

    I am having trouble trying to figure out how to convert this code from VB6 to .Net.

    It checks to see if the user actually right clicks on a selectable item or in blank space. If it is a selectable item, the popup menu appears. If it is in blank space, nothing happens.

    I don't know if this is the best way to do this, but it worked so I used it.

    Thanks!


    VB Code:
    1. Private Sub lvCollections_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.  
    3. Dim i As Integer
    4.  
    5.     'Clear all highlighted items
    6.     Set lvCollections.DropHighlight = Nothing
    7.  
    8.     'Check if right mouse button was pressed
    9.     If Button = vbRightButton Then
    10.        
    11.         'Clear all selected items
    12.         For i = 1 To lvCollections.ListItems.Count
    13.             lvCollections.ListItems(i).Selected = False
    14.         Next
    15.                    
    16.         'Using the mouse cords, do a HitTest to see if there is a selectable item.
    17.         'If there is, make it the selected item and highlight it.
    18.         Set lvCollections.SelectedItem = lvCollections.HitTest(X, Y)
    19.         Set lvCollections.DropHighlight = lvCollections.HitTest(X, Y)
    20.  
    21.         On Error GoTo err
    22.        
    23.         'If there was not an item selected, an error will be returned on the next line
    24.         'and jump to the err: code. If an item was selected, the popup menu will be displayed.
    25.         If Len(lvCollections.SelectedItem) <> 0 Then
    26.             PopupMenu mnuTree
    27.         End If
    28.  
    29.     End If
    30.  
    31. Exit Sub
    32.  
    33. err:
    34.     err.Clear
    35.     On Error GoTo 0
    36.  
    37. End Sub
    Last edited by spdracr; Jan 13th, 2004 at 01:10 PM.

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    like this maybe ...
    VB Code:
    1. Private Sub ListView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseUp
    2.         Dim lvi As ListViewItem = ListView1.GetItemAt(e.X, e.Y)
    3.         If Not lvi Is Nothing Then
    4.             '/// code to handle your menu here.
    5.         Else
    6.             MessageBox.Show("no item selected")
    7.         End If
    8.     End Sub
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Lively Member spdracr's Avatar
    Join Date
    Oct 2003
    Location
    Kansas
    Posts
    115
    Great, it works...
    Last edited by spdracr; Jan 13th, 2004 at 01:07 PM.

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