Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Context menu on listbox

Status
Not open for further replies.

TipGiver

Programmer
Sep 1, 2005
1,863
Hi,

<VB.NET 2005>
A pretty simple question: I have assigned a context menu to a listbox. The menu does not appear when there is an item selected. It does not appear wherever i right-click on the listbox.

Can you suggest a way to fix it?

Thanks
 
Not sure you are looking for this... Here is a snippet that shows context menu on right-click of mouse.

Code:
   Private Sub ListBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseUp
        If e.Button = Windows.Forms.MouseButtons.Right Then
            With ContextMenuStrip1
                .Show(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y)
            End With
        End If

USING VB2005 EXPRES

________________________________________________________
Zameer Abdulla
Help to find Missing people
All cats love fish but fear to wet their paws..
 
Forgot to copy lat line
Code:
    Private Sub ListBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseUp
        If e.Button = Windows.Forms.MouseButtons.Right Then
            With ContextMenuStrip1
                .Show(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y)
            End With
        End If
  [b]  End Sub[/b]

________________________________________________________
Zameer Abdulla
Help to find Missing people
All cats love fish but fear to wet their paws..
 
Hi Zameer,

The good on the context menus is that you can assign it to any control at design-time also. I do from the properties of the listbox: contextmenu=(none) -> contextmenustrip1.
By this, I do not have to write any code like the above so as to show it.

I think that your code works fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top