Reusing RadMenuItems

5 posts, 0 answers
  1. Stefan Lorenz
    Stefan Lorenz avatar
    13 posts
    Member since:
    May 2010

    Posted 14 Dec 2010 Link to this post

    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
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 14 Dec 2010 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Stefan Lorenz
    Stefan Lorenz avatar
    13 posts
    Member since:
    May 2010

    Posted 15 Dec 2010 Link to this post

    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
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 15 Dec 2010 Link to this post

    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
  6. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 16 Dec 2010 Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready