Context Menus Overview
RadTreeView supports its own built-in Context Menus. The Context Menu can be defined declaratively (in the aspx page), in the ContextMenus collection editor in the designer or in the code-behind. You can assign to each Node its own Context Menu using the ContextMenuID property of RadTreeNode. If no ContextMenuID is specified, the first instance from the ContextMenu collection will be assigned to the Node. Context Menus can be multi-leveled. To disable the context menu for a given Node, set the EnableContextMenu property to False.
The example below defines both the RadTreeView structure and a Context Menu, inline. To the first root Node, "Trouble Ticket" is assigned the "HelpDeskMenu" Context Menu, while the other two root Nodes have the EnableContextMenu property set to False. The Context Menu has two items in a single level - "Add" and "Delete". Also note that the OnContextMenuItemClick event is handled. In the OnContextMenuItemClick event handler, the RadTreeViewContextMenuEventArgs parameter makes both the Menu Item and the tree Node available. In the example code the event handler checks to see what is the value of the Menu Item and executes code respectively for "Add" or "Delete". The Node Level property is also checked to verify that the operation is correct in the current context, i.e. deletions should be allowed for trouble tickets, but not for the root Node "Trouble Ticket". The "Add" code adds a Node to the "Trouble Ticket" Nodes collection and expands the Node. The "Delete" code simply calls the selected Node's Remove() method.
<telerik:RadTreeView RenderMode="Lightweight" ID="RadTreeView1" runat="server" Skin="Vista" OnContextMenuItemClick="RadTreeView1_ContextMenuItemClick">
<ContextMenus>
<telerik:RadTreeViewContextMenu runat="server" ID="HelpDeskMenu" ClickToOpen="True"
Skin="Vista">
<Items>
<telerik:RadMenuItem Text="Add" Value="Add">
</telerik:RadMenuItem>
<telerik:RadMenuItem Text="Delete" Value="Delete">
</telerik:RadMenuItem>
</Items>
</telerik:RadTreeViewContextMenu>
</ContextMenus>
<Nodes>
<telerik:RadTreeNode runat="server" Text="Trouble Ticket" ContextMenuID="HelpDeskMenu">
</telerik:RadTreeNode>
<telerik:RadTreeNode runat="server" Text="Equipment Request" EnableContextMenu="false">
</telerik:RadTreeNode>
<telerik:RadTreeNode runat="server" Text="Help Desk Question" EnableContextMenu="false">
</telerik:RadTreeNode>
</Nodes>
</telerik:RadTreeView>