I have added a checkbox column to my columnset for a treeview which is bound to a dataset. The viewstyle is grid. I've added a handler to the checkbox editor to recursively set the checkbox value for all the children for a node.
private void chkIsSelected_ValueChanged(object sender, EventArgs e) { // Propagate the checkbox value to the children. PropagateCheckbox(treeHierarchy.ActiveNode, (bool)((CheckEditor) sender).Value); }
private void PropagateCheckbox(UltraTreeNode parentNode, bool isChecked) { // Propagate the checkbox value to the childern. foreach (UltraTreeNode childNode in parentNode.Nodes) { childNode.Cells["IsSelected"].Value = isChecked; PropagateCheckbox(childNode, isChecked); } }
This works fine with one strange behavior. When I first load the tree, and the user checks the top node checkbox, then the top node checkbox remains unchecked, but all the children are checked. Otherwise, this technique works great.
If I select the top checkbox a second time, then it is checked, and the children are checked. So, the strange behavior is only on the first attempt to check to topmost node.
Here is the code I use to attach the event handler.
CheckEditor editor = new CheckEditor();editor.ValueChanged += new EventHandler(chkIsSelected_ValueChanged);
If I remove the event handler, then the checkbox behaves as expected. In other words, the checkbox is checked on the first attempt.