Context Menu and Listview

rfazendeiro

Centurion
Joined
Mar 8, 2004
Messages
110
Hi ppl,

I have populated my listview with items form by database. I now want to add 2 context menu for diferent purpose im my list view:

1. If a user right clicks in an item that exist in my list view i want to show a context menu with options like "properties", "Delete", "edit", etc.

2. If a user right clicks in the list view where there is no items i want to show a diferent context menu like "add new item", "refresh", "list view", etc

How can i do this? how do i know that the user right clicked on an item?

thanks to all
 
The following seems to work:

Visual Basic:
    Private Sub ListView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown

        If Not (ListView1.GetItemAt(e.X, e.Y) Is Nothing) Then
            ListView1.ContextMenu = mnuItem
        Else
            ListView1.ContextMenu = mnuNoItem
        End If

    End Sub
 
Back
Top