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:
Private Sub lvCollections_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Integer
'Clear all highlighted items
Set lvCollections.DropHighlight = Nothing
'Check if right mouse button was pressed
If Button = vbRightButton Then
'Clear all selected items
For i = 1 To lvCollections.ListItems.Count
lvCollections.ListItems(i).Selected = False
Next
'Using the mouse cords, do a HitTest to see if there is a selectable item.
'If there is, make it the selected item and highlight it.
Set lvCollections.SelectedItem = lvCollections.HitTest(X, Y)
Set lvCollections.DropHighlight = lvCollections.HitTest(X, Y)
On Error GoTo err
'If there was not an item selected, an error will be returned on the next line
'and jump to the err: code. If an item was selected, the popup menu will be displayed.
If Len(lvCollections.SelectedItem) <> 0 Then
PopupMenu mnuTree
End If
End If
Exit Sub
err:
err.Clear
On Error GoTo 0
End Sub