Community journal

The latest from the MySQL community

Ideas, releases, practical guides, and perspectives from the people building with MySQL.

Follow the feed
Showing entries 41 to 41 of 41 « Previous | Next »
Displaying posts with tag: Expo (reset)
Cancel the Display of a ContextMenuStrip in VB.NET 2005

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.

« Previous | Next »