Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to perform nested ContextMenu implementation?

I have this menu like this:

// open context menu
var contextMenu = new ContextMenu();
var versionsMenu = new ToolStripDropDownMenu() {Text = "Version"};
StaticHelpers.GetPackageVersions(textBlockSelected.Text).ForEach(f=> versionsMenu.Items.Add(f));
var scheduleMenu = new ToolStripMenuItem {Text = "Schedule"};
var argumentsMenu = new ToolStripMenuItem() {Text = "Arguments"};
var removeMenu = new ToolStripMenuItem {Text = "Remove"};

//show context menu
contextMenu.Items.Add(versionsMenu);
contextMenu.Items.Add(scheduleMenu);
contextMenu.Items.Add(argumentsMenu);
contextMenu.Items.Add(removeMenu);

//add handlers
// executeMenu.Click += (o, args) => { ExecutePackage(sender); };

//open context menu
contextMenu.IsOpen = true;

I have tried MenuItems instead of ToolStripMenuItem or ToolStripDropDownMenu but could not find any documentation or examples anywhere about how you can make these things nested, for example, when the user right clicks on one of my controls I want to show this menu:

  • Version
  • Schedule
  • Arguments
  • Remove

If the user hovers over version, I want another contextMenu to extend and show the following:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  • V1.0
  • V1.1
  • V1.2

How can I achieve this functionality?

>Solution :

To add a sub-menu, you take an existing item and do the same to it:

var versionsMenu = new ToolStripMenuItem();
versionsMenu.DropDownItems.Add(nestedItem);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading