Use the mousedown event of the listbox, and check for the mouse button. If it's the right button then count the selected items and set the contextmenustrip arcordingly
vb Code:
Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown If e.Button = Windows.Forms.MouseButtons.Right Then If ListBox1.SelectedIndices.Count > 0 Then ListBox1.ContextMenuStrip = Me.ContextMenuStrip1 Else ListBox1.ContextMenuStrip = Nothing End If End If End Sub




Reply With Quote