Check branch only when CTRL key is pressed?

I would like to set the subChecked only when the CTRL key is checked, is this possible?



So far I can see that I can set the SubChecked as true or false but not dependent on Keyboard button press.



Thanks



John

If you are using 3-state tree, it not possible, because it doesn’t allow checking parent and having some child items unchecked in the same time.
If you are using 2-state tree, it can be done with a bit of customization

in dhtmlxtree.js

if (!this.treeNod.callEvent(“onBeforeCheck”,[this.parentObject.id,this.parentObject.checkstate]))

can be replaced with

if (!this.treeNod.callEvent(“onBeforeCheck”,[this.parentObject.id,this.parentObject.checkstate,(e||event)]))


after that you will be able to use

tree.attachEvent(“onBeforeCheck”,function(id,check,e){
if (e.ctrlKey) exec_sub_check_logic();
return true;
})



I have made the change to the js file and added this script to the page:



tree.attachEvent(“onBeforeCheck”,function(id,state,e){
  if (e.ctrlKey) doOnCheck(id,state);
  return true;
 })
  
 function doOnCheck(nodeId,state){
  if (state == 1) {
   tree.setSubChecked(nodeId,true);
   } else {
   tree.setSubChecked(nodeId,false);
  }
  }



However, when I check the parent box while it is unchecked (with CTRL key pressed) it just checks the parent and not the children. When I then press the parent again (with CTRL key pressed), it unchecks the parent and checks the children.



Any ideas?



Thanks, John


Just changed the above to use the onCheck instead of onBeforeCheck and its working fine.



John