dhtmlxTree - can right click mouse (context menu) on a node

I dont want a user to have to left click mouse to select a node and then right click to use context menu on that node. So can right click aslo select that node?



1) select and hightlight a tree node

2) right click on another tree node to get context menu and then have either:-

–a) focus/select the node right clicked on or else

–b) not show a menu option



Using

attachEvent(“onClick”, treeonButtonClick);



tree.attachEvent(“onBeforeContextMenu”, function(itemId) {

tree.focusItem(iitemId,true); // try and move selected node to this node ie hightlight it - but does not work


Hello,


try to use selectItem method instead of focusItem to select an item:


tree.attachEvent(“onBeforeContextMenu”, function(itemId) {
tree.selectItem(itemId,true);


return true


}




It worked! Apologies Alex, I could have sworn I tried tree.selectItem(itemId,true); but without success. I already use this elsewhere in my code.


Still have a problem - I’m trying to multi select items and then use the (right mouse click) context menu to do an action on those selected nodes.



I’m using tree.enableMultiselection(true,true); but theres a problem if :-



1) I do a multiselect on nodes 1,2,3 - they are selected/highlighted



2) but if I then right click on say node 4 then the context menu is for node 4 even though it is not selected/highlighted.



3) Possible solution - use tree.selectItem(itemId,true);



If I now repeat 1 and 2 above then this time nodes 1,2,3 are deseleted and node 4 is selected/highlighted - so thats good the context menu is now associated with that selected. But its not a solution because if I select nodes 1,2,3 and right click on 3 then nodes 1,2 are deselected only node 3 is selected.


The selectItem method can have the 3rd parameter. It preserves the previous selection:


tree.attachEvent(“onBeforeContextMenu”, function(itemId) {
tree.selectItem(itemId,true,true);
return true
}