This project is read-only.


Bug in Nested Context Menus


See full discussion:

Essentially, nesting context menu items can make the indexes go out of whack.


First of all, thanks for this great code. I needed to use your code since windows 8 does not support multilevel item in SendTo which was supported in Windows XP, but I had a problem in certain situation. When using your code, I needed to add a subitem before adding the actual menu items in order to obtain a tree like structure. What I mean was a structure like this:

Context Menu->
_______________________Run Menu 1 Job
_______________________Run Menu 2 Job

What happens is when I click the first item of 'SubMenu' that is 'Run Menu 1 Job', it does not trigger the event attached to 'Run Menu 1 Job' (itemCountLinesv1), but it triggers the event of the second item that is the event of 'Run Menu 2 Job' (itemCountLinesv2). And when I click the second item of 'SubMenu' that is 'Run Menu 2 Job', it does not trigger its event (itemCountLinesv2). I tried this with up to six items under SubMenu, the pattern does not change, always triggers the next one's event except the last item wich does not trigger anything. I could not resolve this, would you be able to help me (For testing, I used both VS2008,.NET4.0 SP1 in 32 bit XP and VS2012 with first update,.NET4.5 in 64 bit Windows8; no difference).

Kind Regards


// Create the menu strip.
    protected override ContextMenuStrip CreateMenu()
        //  Create the menu strip.
        var menu = new ContextMenuStrip();

        ToolStripMenuItem SubMenu;

        SubMenu = new ToolStripMenuItem("SubMenu");

        var itemCountLinesv1 = new ToolStripMenuItem
            Text = "Run Menu 1 Job",
        itemCountLinesv1.Click += SubMenuItemClickv1;

        var itemCountLinesv2 = new ToolStripMenuItem
            Text = "Run Menu 2 Job",
        itemCountLinesv2.Click += SubMenuItemClickv2;

        return menu;
Closed Jan 26, 2013 at 2:50 PM by dwmkerr
Issue resolved in v.14