We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Programatically add submenu to context menu

I am trying to programmatically add a submenu item to a context menu. I currently have the context menu working correctly but I would like to add another menu item to the context menu which already exists and add the ability to open a submenu item from the main context menu. Also, the new submenu needs to have a number of items with a checkbox next to each choice. If anyone can provide assistance that would be great, thanks.


8 Replies

IM Iniyen M A Syncfusion Team July 8, 2011 08:13 AM UTC

Hi Thomas,

Thanks for your interest in Syncfusion products.

You can achieve your requirement by enabling MenuItem's "CheckOnClick" property, which can make it behave like a CheckBox.

Please let us know if you need further assistance.

Regards,
Iniyen M.A.



TD Thomas DiLello July 8, 2011 05:27 PM UTC

What about creating subitems in a context menu? How do I do that?



IM Iniyen M A Syncfusion Team July 11, 2011 05:27 AM UTC

Hi Thomas,

Thanks for the update.

You can achieve your requirement by using the Specific ToolStripItem's DropDownItems.AddRange() method. For more information I have included the sample as follows, Kindly have a look on it.

[Sample]
http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=ContextMnustrpex_thrcode-1451971708.zip

Please let us know if you need further assistance.

We are glad to help you out.

Regards,
Iniyen M.A.



TD Thomas DiLello July 11, 2011 03:21 PM UTC

Hi, thanks for the update on this.

However, I am using BarItems instead of ToolStripMenu as that is what the project calls for. How can I use populate a BarItem with a submenu and display that in a sub context menu? Thanks.

Tom



TD Thomas DiLello July 12, 2011 09:31 PM UTC

Hello? Are you there?

I have figured out that I need to use a DropDownBarItem object. Now can you tell me how I can use this object to display submenu items? I have a menu item of type DropDownBarItem but the menu it displays is blank. I tried setting that class's PopupControlContainer property. I set that properties ContextMenuStrip property but I am not seeing anything on that menu. Here is how I build my submenu:

private PopupControlContainer BuildSubMenu()
{
ContextMenuStrip strip = new ContextMenuStrip();
strip.Items.AddRange(new[] {new ToolStripMenuItem("Sub menu Item#1")});

PopupControlContainer popupControlContainer = new PopupControlContainer
{ContextMenuStrip = strip, ParentControl = this};

return popupControlContainer;
}



IM Iniyen M A Syncfusion Team July 13, 2011 11:26 AM UTC

Hi Thomas,

Thanks for the update.

We do not have support to have BarItems in ContextMenuStripEx.

Please let us know if you need further assistance.

Regards,
Iniyen M.A.




TD Thomas DiLello July 13, 2011 02:25 PM UTC

Hi,

Could you tell me more about PopupControlContainer. I am setting the PopupControlContainer property on a DropDownBarItem. How do I display list of menu items in a PopupControlContainer?

Thanks



VS Vallarasu S Syncfusion Team July 14, 2011 08:02 AM UTC

Hi Thomas,

Thanks for the update.

You should use ParentBarItems in place of BarItem where a list of child BarItems needs to be shown, and Checked property of the BarItem can be toggled upon click to make it behave like a checkBox.

I have attached a sample to demonstrate how PopupMenu can be associated with a control. Refer the sample and let me know if this helps.

PopupControlContainer is intended to host objects of type 'Control', and is not the best way to implement popup menus.

Regards
Vallarasu S.



ContextMenuSample_aef47e4.zip

Loader.
Live Chat Icon For mobile
Up arrow icon