Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
710
Propagate Checkbox
posted

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.