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

Open context menu on left click instead of right click

2 Answers 434 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 06 Nov 2012, 09:24 AM
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:

ALL COURSES [ROOT]
COURSE GROUP NAME
COURSE
COURSE

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" >
                <ContextMenus>
                    <telerik:RadTreeViewContextMenu ID="UserGroupContextMenu" runat="server">

AND here is the JavaScript being used:
function UsersTreeView_onClientContextMenuShowing(sender, args) {
    sender.unselectAllNodes();
    var treeNode = args.get_node();
    treeNode.set_selected(true);
    //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();
    menuItem.get_menu().hide();

    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":
            break;
    }
}

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

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 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 06 Nov 2012, 10:38 AM
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);
           args.set_cancel(true);
       }

Hope this will be helpful.

Regards,
Plamen
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.
0
James
Top achievements
Rank 1
answered on 06 Nov 2012, 10:52 AM
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
Tags
TreeView
Asked by
James
Top achievements
Rank 1
Answers by
Plamen
Telerik team
James
Top achievements
Rank 1
Share this question
or