This is a migrated thread and some comments may be shown as answers.

Context Menu with sub menus via designer

6 Answers 235 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Brendan
Top achievements
Rank 1
Brendan asked on 24 Oct 2014, 01:22 AM
Is it possible to create a right click Rad context menu in the designer with submenu items?  Or can it only be done in code.

Is there any suitable rad menu that can be created in the designer with sub menus and be used as a right click menu?

Otherwise I can use the standard .Net menu I guess.

Thanks

6 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 24 Oct 2014, 03:54 PM
Hi Brendan,

Thank you for writing.

Yes it is possible, first drag and drop RadContextMenu onto the form (the menu is added at the bottom left corner - see step 1 image). Then you can just open the smart tag (step 2 image, click the edit items link and add some items to the menu (see the step 3 image). 

Please let me know if there is something else I can help you with. 
 
Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Brendan
Top achievements
Rank 1
answered on 24 Oct 2014, 04:24 PM
Hi Dimitar, I am familiar with the RadContextMenu, it Is the sub menus that I am having trouble with.  Please see the attached image that I created with the Microsoft ContextMenuStrip.  How do I create the same submenu items in the RadContextMenu designer?

If I do it through code do I need to dispose of all the RadContextMenu items every time the menu is closed?  If I don't will this lead to increased memory usage?

Thanks.
0
Accepted
Dimitar
Telerik team
answered on 27 Oct 2014, 04:52 PM
Hello Brendan,

Thank you for writing back.

Each RadMenuItem has its own collection of items (first attached image) and you can add items to it in the very same way (second attached image). The result will look like in the third attached image.

Creating the items in the designer also creates code for them. It is located in the InitializeComponent method you can see it by opening the forms designer.cs file (the last attached image). In this case the items will be automatically disposed when there are no reference to them and the form is disposed. You do not need to manually dispose the items since they will not consume much memory and recreating them actually can take more memory since the .NET garbage collector in non-deterministic and you cannot tell for sure when the garbage will be collected. 

I hope this helps.

Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Brendan
Top achievements
Rank 1
answered on 27 Oct 2014, 05:51 PM
Thanks I see the sub items now
0
Brendan
Top achievements
Rank 1
answered on 27 Oct 2014, 07:53 PM
Hi Dimitar, I wanted to clarify dynamic Context Menu creation instead of using the designer.  If I create a custom menu in code every time a user right clicks a grid do I need to dispose of the menu, its items, and the handlers after the event click, or will garbage collection handle everything?  There could be many clicks during the lifetime session of the program.

Example;
Private contextMenu1 As RadContextMenu
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    contextMenu1 = New RadContextMenu()
    Dim menuItem1 As New RadMenuItem("Item 1")
    AddHandler menuItem1.Click, AddressOf rmi1_Click
    Dim menuItem2 As New RadMenuItem("Item 2")
    AddHandler menuItem2.Click, AddressOf rmi2_Click
    contextMenu1.Items.Add(menuItem1)
    contextMenu1.Items.Add(menuItem2)
End Sub
0
Dimitar
Telerik team
answered on 29 Oct 2014, 07:44 AM
Hello Brendan,

Thank you for writing back.

The memory will be allocated when the items and the context menu are created and it will be freed once they are not referenced anywhere (or there are out of scope). It will not depend on the number of times the menu is used or how many times the user has clicked on item. More information is available here: Garbage Collection.

I hope this helps.

Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ContextMenu
Asked by
Brendan
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Brendan
Top achievements
Rank 1
Share this question
or