ContextMenu and dynamically generated items

Feb 4, 2014 at 5:24 PM

could you please tell me if there is any way to create dynamic context menu items (generated on fly) with SharpShell?

I want some of the drop down items to be added after the root item is expanded not on the CreateMenu() method. I have tested plenty of available events but none of them gets triggered (MouseEnter, DropDownOpened, Enter etc.)

Thank you in advance for any help.
Feb 4, 2014 at 8:06 PM
Only in the current development version would this be possible, because in this version I've wired in some of the more advanced functionality offered. I can give you access to the development branch if that would help - the API is unlikely to change from what it is now and will be released soon anyway. Let me know if you need it urgently - frankly from my point of view another pair of eyes to check it out and have a test would be useful.
Feb 5, 2014 at 4:39 PM
Oh that's a great news!

I guess I can wait a week or two :) Do you know the approximate date the new version will be released?

On the other hand I test the development version if it works in my scenario. So if it is not to much trouble I'll be happy to take a look.

Feb 9, 2014 at 1:53 PM
Cool, I'm expecting the release of 2.1 to be mid february, it's going to be a close one to get this feature in but I'll keep you posted.

All the best,


Mar 11, 2014 at 11:59 AM
Hi Dave,

Is it possible to create dynamic context menu items with the last release (2.1)?

I would like to create the drop down items of a context menu item when the user clicks on it, to have better performances and generate the context menu buttons only when needed.

I tried to use the ToolStripMenuItem.DropDownOpening event in the CreateMenu() method but it doesn't seem to be fired.
 protected override System.Windows.Forms.ContextMenuStrip CreateMenu()
            //  Create the menu strip.
            ContextMenuStrip menu = new ContextMenuStrip();

            //  Create a drop-down item.
            ToolStripMenuItem itemDropdown = new ToolStripMenuItem
                Text = "Drop-down item test"

            // Add a temporary submenu item

            // Create the submenu items when the user opens the drop down submenu
            itemDropdown.DropDownOpening += new EventHandler(itemDropdown_DropDownOpening);
            //  Add the item to the context menu.

            //  Return the menu.
            return menu;

        void itemDropdown_DropDownOpening(object sender, EventArgs e)
            // Message box (not displayed)
            MessageBox.Show("Dropdown opening");
            ToolStripMenuItem item = sender as ToolStripMenuItem;

            // Some code not shown here checks which buttons must be created in function of the SelectedItemPaths properties...

            // Creates submenus items...
            ToolStripMenuItem itemShowSettings = new ToolStripMenuItem("Show settings");
            itemShowSettings.Click += (sender2, args) => Clicked();

        private void Clicked()
Thank you, and thanks for your great work!
Mar 12, 2014 at 10:27 AM

With 2.1, no, but I'm aiming to get this in for 2.2 - the task is at:

If you watch it you'll see when it's done.


Mar 12, 2014 at 10:42 AM
Hi Dave, thank you!
Oct 7, 2015 at 2:52 PM
Edited Oct 7, 2015 at 2:52 PM
@JulienVan I wanted to the exact same thing, after a little struggle I figured out a way to do it, I just added an example and made a pull request, I have written an article to explaining this. (links below)


Pull request: