I encountered a bug recently in my tool where I could right-click on a listview, even if I was not right-clicking on a listview item, and still use the item related entries of a contextMenuStrip. The problem is that unlike the TreeView, the ListView does not allow you to assign a ContextMenuStrip to individual items, just the control as a whole.
The solution was to use the new Opening event of the ContextMenuStrip:
Private Sub eventMenu_Opening(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles eventMenu.Opening
If lvwEvents.SelectedItems.Count = 0 Then
e.Cancel = True
End If
End Sub
By setting e.Cancel to True, the menu is never shown. I determine whether an item was clicked on by checking the count of selecteditems.