View ContextMenu only on the parentnode

4 posts, 2 answers
  1. Colince
    Colince avatar
    11 posts
    Member since:
    Apr 2013

    Posted 08 Jul 2013 Link to this post

    Hi, 
    I have an issue regarding the view of tne contextMenu in the RadTreeView. I would like to view the contextMenu only on the parentnode and not on the child node while right_clicking  the mouse.
    Thank you for any help

    <telerik:RadTreeView ID="rtvCatalog" runat="server" EnableDragAndDrop="True"
                         OnNodeDrop="rtvCatalog_HandleDrop" MultipleSelect="false"
                         EnableDragAndDropBetweenNodes="true"
                         OnClientNodeDropping="onNodeDropping"
                         OnClientMouseOver="onNodeMouseOver"
                         OnClientMouseOut="onNodeMouseOut"
                         AllowNodeEditing="true"
                         OnNodeEdit="rtvCatalog_NodeEdit"
                         CausesValidation="false" Width="100%"
                         OnContextMenuItemClick="onMenuItemClick">
        <ContextMenus>
            <telerik:RadTreeViewContextMenu ID="mnuGroup" runat="server">
                <Items>
                    <telerik:RadMenuItem Text="Order ascending" Value="Ascending"
                                     ImageUrl="~/Images/Sort-ascend.png" runat="server">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem Text="Order descending" Value="Descending"
                                     ImageUrl="~/Images/Sort-descend.png" runat="server">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem Text="Copy group in" Value="Select">
                    </telerik:RadMenuItem>
                </Items>
            </telerik:RadTreeViewContextMenu>
        </ContextMenus>
    </telerik:RadTreeView>
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 09 Jul 2013 Link to this post

    Hi Collince,

    Try attaching the following JavaScript code in the OnClientContextMenuShowing client event of the RadTreeView. The ContextMenu will be shown for root level elements only.

    JavaScript:
    <script type="text/javascript">
        function onClientContextMenuShowing(sender, args) {
            if (args.get_node().get_level() != 0) {
                args.set_cancel(true);
            }
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Kate
    Admin
    Kate avatar
    1898 posts

    Posted 09 Jul 2013 Link to this post

    Hi Colince,

    To get the context menu appear only to specific nodes from the RadTreeView control you can use the EnableContextMenu property of the nodes and set it to false for the child nodes.

    Regards,
    Kate
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  5. Colince
    Colince avatar
    11 posts
    Member since:
    Apr 2013

    Posted 09 Jul 2013 Link to this post

    Many thanks to all,
    I  tried the javascript's function and it works very well.
Back to Top