Open context menu on left click instead of right click

3 posts, 0 answers
  1. James
    James avatar
    20 posts
    Member since:
    Jan 2012

    Posted 06 Nov 2012 Link to this post

    Hi there, I have a radtreeview which has a context menu which works perfectly on right click. When a user right clicks on a node in the tree the context menu will appear with options such as "delete [course name]", "edit [course name]", and "add [course name]". Where [course name] is is where the name of the node they are clicking on will go which also works perfectly. My tree view is like this:


    Each level on the tree has a slightly different context menu as some have more options than the others. So far I have managed to get a context menu to appear on left click, but all this does is make the biggest context menu appear no matter which node is clicked on and where the course name should be [course name] is displayed instead of the actual course name. But when I right click and then left click the context menu works fine but right click is needed before hand.

    Here is part of my asp tree code:
    <telerik:RadTreeView ID="UsersTreeView" runat="server" Height="100%" Width="400px"
                    OnNodeEdit="UsersTreeView_NodeEdit" OnNodeExpand="UsersTreeView_NodeExpand"
                    OnNodeCollapse="UsersTreeView_NodeCollapse" AllowNodeEditing="True" EnableDragAndDrop="True"
                    OnContextMenuItemClick="TreeView_ContextMenuItemClick" OnClientContextMenuShowing="UsersTreeView_onClientContextMenuShowing"
                    OnClientContextMenuItemClick="UsersTreeView_onClientContextMenuItemClicking"  OnClientNodeClicking="UsersTreeView_onNodeClicking" 
                    MultipleSelect="True" OnNodeDrop="UsersTreeView_HandleDrop" >
                        <telerik:RadTreeViewContextMenu ID="UserGroupContextMenu" runat="server">

    AND here is the JavaScript being used:
    function UsersTreeView_onClientContextMenuShowing(sender, args) {
        var treeNode = args.get_node();
        //enable/disable menu items
        UsersTreeView_setMenuItemsState(args.get_menu().get_items(), treeNode);

    function UsersTreeView_onClientContextMenuItemClicking(sender, args) {
        var menuItem = args.get_menuItem();
        var treeNode = args.get_node();

        switch (menuItem.get_value()) {
            case "add":
            //case "addroot":
            case "edit":
            //case "user_viewcourses":
            case "user_assigncourses":
            case "group_assigncourses":
            case "group_assigncoursessub":
            //case "moveroot":
            case "delete":

    AND currently for left click I am using this:
        function UsersTreeView_onNodeClicking(sender, args) {
                var domEvent = args.get_domEvent();
                var menu = $find("<%= UserGroupContextMenu.ClientID %>");

    Now I do realize that with my left click code this is needed somewhere:
    UsersTreeView_setMenuItemsState(args.get_menu().get_items(), treeNode);

    Its used within the default right click code to decide the correct context menu needed but I've tried adding it to my left click code and just cant seem to get it working. I have searched like mad round the forums and Google but for my specific problem I have been unable to find an answer, for all I know it could be impossible to do? 

    Thanks, James
  2. Plamen
    Plamen avatar
    2817 posts

    Posted 06 Nov 2012 Link to this post

    Hello James,

    You can try opening the context menu as in the code below:
    function onNodeClicking(sender, args) {
               var domEvent = args.get_domEvent(),
                   node = args.get_node(),
                   menu = node.get_contextMenu();
               sender.showNodeContextMenu(node, domEvent);

    Hope this will be helpful.

    the Telerik team
    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 their blog feed now.
  3. James
    James avatar
    20 posts
    Member since:
    Jan 2012

    Posted 06 Nov 2012 Link to this post

    I feel like a moron now! Looking at your code it makes so much sense now that it would work that way. Thank you so much! And thanks again for reply to my other post in the other thread. Your a legend
Back to Top