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

RadTreeView ContextMenu for certain nodes only

1 Answer 73 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Daica
Top achievements
Rank 1
Daica asked on 11 Mar 2019, 05:13 AM

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?

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Mar 2019, 08:41 AM
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.
Tags
ContextMenu
Asked by
Daica
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or