views:

235

answers:

2

Hi! I made context menu for UltrawinGrid, when i click right mouse button then the context menu open.

This is the code that I use for my menu:

Private Sub ShowContextMenu(ByVal mousePoint As Point)
        Dim cMenu As ContextMenu = New ContextMenu


        cMenu.MenuItems.Add("Delete")
        cMenu.MenuItems.Add("Copy")
        cMenu.MenuItems.Add("Paste")

        cMenu.Show(UltraGrid1, mousePoint)

    End Sub

Now I want when I click on context menu item, for example delete, to call function that gone do something, how i can do this? How I can make connection between menu items and functions?

+2  A: 

You have to add an event handler:

cMenu.MenuItems.Add("Delete", mnuDelete_OnClick)

And the method:

Private Sub mnuDelete_OnClick(sender As System.Object, e As System.EventArgs)
End Sub
p2u
A: 

Not sure about the UltrawinGrid, but typically you should be able to associate a Context Menu to a control. Context Menu control is available in your toolbox as ContextMenuStrip. Drop that in your designer, specify the menu item and wire up the event through the designer. That is much easier way to do it.

For whatever reason if you cant do the above, you will have to manually for each menu item wireup your own event handler in the code like this:

    cMenuSubItem1.Click +=new EventHandler(tesToolStripMenuItem_Click);
Fadrian Sudaman