I have Windows Form App. I have added Context Menu that appear when you right mouse click over the listbox. But some reason I could not figure out how to catch onClick event for ContextMenu- Menu-Item. In also need to grab item index from the listbox while user click on menu-item. If I am clicking the left mouse button i would use lstCustomer.SelectedItems(0).SubItems(2).Text, but I am not sure would it be the same case or not when user right clicks over the item and pick menu-item from Context Menu.
Dashboard.vb
Public Class Dashboard
Private Sub Dashboard_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
LoadContextMenu()
End Sub
Private Sub LoadContextMenu()
Dim contxMnu As New ContextMenu()
Dim menuItem1 As New MenuItem()
Dim menuItem2 As New MenuItem()
contxMnu.MenuItems.AddRange(New MenuItem() {menuItem1, menuItem2})
menuItem1.Index = 0
menuItem1.Text = "Do Something 1"
menuItem2.Index = 1
menuItem2.Text = "Do Something 2"
Me.ContextMenu = contxMnu
End Sub
End Class
I’m not sure whether I understand exactly what you want to get. If it’s all about action that handles the Click event you can do something like this:
…and events are: