RadTreeView ContextMenu for certain nodes only

2 posts, 1 answers
  1. Daica
    Daica avatar
    4 posts
    Member since:
    Mar 2019

    Posted 11 Mar Link to this post

    Hello,

    I am wondering if it is possible to set a RadContextMenu for certain nodes when creating them programmatically.

    For example, my tree will look something like this:

    [MAIN NODE]

        [Child1]

        [Child2]

    [MAIN NODE 2]

        [Child1]

        [Child2]

     

    Would it be possible to have a RadContextMenu only for the parent node, and then a separate RadContextMenu for all the Child nodes?

     

  2. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3273 posts

    Posted 12 Mar Link to this post

    Hello, Daica,    

    In order to restrict the context menu showing, it is appropriate to cancel the RadTreeView.ContextMenuOpening event considering the Node.Level in the TreeViewContextMenuOpeningEventArgs. This property indicates whether the node is a parent one or a sub node:

    public RadForm1()
    {
        InitializeComponent();
     
        this.radTreeView1.AllowDefaultContextMenu = true;
        this.radTreeView1.ContextMenuOpening+=radTreeView1_ContextMenuOpening;
    }
     
    private void radTreeView1_ContextMenuOpening(object sender, Telerik.WinControls.UI.TreeViewContextMenuOpeningEventArgs e)
    {
        if (e.Node.Level!=0)
        {
            e.Cancel = true;
        }
    }

    Additional information about the context menu in RadTreeView is available in the online documentation:

    https://docs.telerik.com/devtools/winforms/controls/gridview/columns/column-types/gridviewcomboboxcolumn
    https://docs.telerik.com/devtools/winforms/controls/treeview/context-menus/modifying-the-default-context-menu

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top