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

Reusing RadMenuItems

4 Answers 111 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Stefan Lorenz
Top achievements
Rank 1
Stefan Lorenz asked on 14 Dec 2010, 03:44 PM
Hi,

I'd like to know if there's a way to "link" items from a RadContextMenu to a RadMenu or vice versa. I want to show the same menu-structure from my contextmenu in the main menu without duplicating everything.

I tried to initialize a context with myMainMenuitem.DropDown. While this works (contextmenu with items from myMainMenuitem shows up), the Items of myMainMenuitem were empty afterwards.

Best regards
Stefan

4 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 14 Dec 2010, 10:23 PM
Hi Stefan,

I've tried a really basic example of this and it seems to work. I added a RadContextMenu to a RadListControl and the same menu items to the RadMenu.

On my form, I have a RadMenu, a RadListControl and a RadtextBox. See screenshot.

Imports Telerik.WinControls.UI
  
Public Class Form1
  
  
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.RadMenu1.Items.AddRange(GetMenuItems().ToArray())
        Dim contextMenu As New RadContextMenu()
        contextMenu.Items.AddRange(GetMenuItems().ToArray())
  
        Dim radContextMenuManager As New RadContextMenuManager()
        radContextMenuManager.SetRadContextMenu(Me.RadListControl1, contextMenu)
    End Sub
  
    Private Function GetMenuItems() As List(Of RadMenuItem)
        Dim menu1 As New RadMenuItem("Menu Item 1")
        Dim menu2 As New RadMenuItem("Menu Item 2")
  
        AddHandler menu1.Click, AddressOf Menu1_Click
        AddHandler menu2.Click, AddressOf Menu2_Click
  
        Dim menus As New List(Of RadMenuItem)
        menus.Add(menu1)
        menus.Add(menu2)
        Return menus
    End Function
  
    Private Sub Menu1_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.RadTextBox1.Text &= "Menu 1 Clicked" & Environment.NewLine
    End Sub
  
    Private Sub Menu2_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.RadTextBox1.Text &= "Menu 2 Clicked" & Environment.NewLine
    End Sub
  
End Class

hope that helps
Richard
0
Stefan Lorenz
Top achievements
Rank 1
answered on 15 Dec 2010, 08:57 AM
Hi Richard,

you duplicated the menuitems. While this is doable, it means that I either have to create that menus from code or deep-clone existing ones. I thought there must be a solution to show an existing menu as a context without duplicating it.

Best regards
Stefan
0
Richard Slade
Top achievements
Rank 2
answered on 15 Dec 2010, 09:54 AM
Hi Stefan,

I may be wrong, but I think the problem there will be that each RadMenuItem needs to have an owner. So which will teh ownder be, the RadMenu or the RadContextMenu.
Richard
0
Stefan
Telerik team
answered on 17 Dec 2010, 01:00 AM
Hi Stefan, 

Thank you for writing.

Richard is absolutely right in his last post. One menu item cannot be parented by two or more parents at the same time.

Thank you Richard for the community effort.  

If there is anything else I can assist you with guys, do not hesitate to contact me.

Kind regards,
Stefan
the Telerik team
Check out the Q1 2011 Roadmap for Telerik Controls for Windows Forms.
Tags
Menu
Asked by
Stefan Lorenz
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Stefan Lorenz
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or