' Select the item right clicked.
Private Sub ListView1_MouseDown(Button As Integer, Shift As _
Integer, x As Single, y As Single)
Dim item As ListItem
If Button = vbRightButton Then
Set item = ListView1.HitTest(x, y)
If item Is Nothing Then
Set item = ListView1.SelectedItem
If Not item Is Nothing Then
item.Selected = False
End If
Else
Set ListView1.SelectedItem = item
End If
End If
End Sub
' Display the popup menu.
Private Sub ListView1_MouseUp(Button As Integer, Shift As _
Integer, x As Single, y As Single)
Dim item As ListItem
If Button = vbRightButton Then
Set item = ListView1.HitTest(x, y)
If item Is Nothing Then
PopupMenu mnuPopupOffItem
Else
mnuPopupOnItemItemSelected.Caption = item.Text
PopupMenu mnuPopupOnItem
End If
End If
End Sub
|