Hi,
A Tree's nodes are: NodeStyle = NodeStyle.CheckBox;
When user checks a node, i programmatically check its child nodes, and programmatically set its parent to CheckState.Indeterminate;
tried listening to the below events:
<treeView_BeforeCheck(object sender, BeforeCheckEventArgs e)> and <treeView_BeforeCheck(object sender, AfterCheckEventArgs e)>
On both events, as i programmatically check o uncheck the boxes, the event is being raised again.
Is there a way to hold the event from firing, if the edit of check box is done programmatically?
else, is there a better practise on doing this?
thanks for suggestions,
R.
Yes, you can use the tree.EventManager.SetEnabled method to enable / disable events temporarily and avoid this kind of recursion.
Thanks for replying Mike.
events do not fire.
below sub is meant to checks child nodes of parent node (not necessary root node).
private void checkChildNodes(UltraTreeNode node,UltraTree tree) { tree.EventManager.SetEnabled(EventGroups.AllEvents, false);foreach (UltraTreeNode utn in node.Nodes) { if (node.CheckedState == CheckState.Unchecked) node.CheckedState = CheckState.Checked; }tree.EventManager.SetEnabled(EventGroups.AllEvents, true); }
{
tree.EventManager.SetEnabled(EventGroups.AllEvents, false);foreach (UltraTreeNode utn in node.Nodes) { if (node.CheckedState == CheckState.Unchecked) node.CheckedState = CheckState.Checked; }tree.EventManager.SetEnabled(EventGroups.AllEvents, true);
tree.EventManager.SetEnabled(EventGroups.AllEvents, false);
if (node.CheckedState == CheckState.Unchecked) node.CheckedState = CheckState.Checked;
node.CheckedState = CheckState.Checked;
}
but only the node calling the sub is actually check. why?
Thanks in advance for suggesting.
Thanks again for replying Mike.
Perfect, recursion does the trick.
Regards,
Joe.
If you want this code to check all nodes and all of the descendents, then you need to call it recursively.