This is a migrated thread and some comments may be shown as answers.

CheckedChanged\Changing not firing

3 Answers 169 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve asked on 12 Nov 2010, 10:43 PM
When I check my nodes, I get the events firing, but when I uncheck them nothing happens...and any additional click doesn't trigger an event....any idea why? :)

private void radTreeView1_NodeCheckedChanged(object sender, RadTreeViewEventArgs e) {
    foreach (RadTreeNode n in e.Node.Nodes){
        n.Checked = e.Node.Checked;
        this.ChangeCheck(n.Nodes, e.Node.Checked);
    }
 
    //Check to see if this entire node is unchecked, then uncheck the parent
    if (e.Node.Parent != null) {
        //If none are checked
        var checkCount = e.Node.Parent.Nodes.Count(x => x.Checked);
        if (checkCount == 0) {
            e.Node.Parent.Checked = false;
        }else if (checkCount == e.Node.Parent.Nodes.Count()){ //If all are checked
            e.Node.Parent.Checked = true;
        }
    }
 
}
 
private void ChangeCheck(RadTreeNodeCollection nodes, bool state){
    foreach (RadTreeNode n in nodes) {
        n.Checked = state;
        this.ChangeCheck(n.Nodes, state);
    }
}

3 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 13 Nov 2010, 12:19 AM
Hi Steve,

I suspect this is happening because you are checking and unchecking nodes inside the checked changed, which is then firing the NodeCheckedChanged again.
Are you wanting to uncheck parent nodes when all of the child nodes are unchecked? If so, then you can just set RadTreeView.TriStateMode to true.

Hope that helps, but let me know if you need more information

Richard
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 13 Nov 2010, 11:34 PM
Thanks for the reply :)

I'm a bit new so Telerik WinForms and I couldn't see this functionality as a property (wasn't obvious to me anyway) so I just tried to do it myself...

So yeah the idea was that checking an item selects all children, and if all children are unselected then the parent becomes unselected as well.  So I shall try the Tristate, thank you :)
0
Richard Slade
Top achievements
Rank 2
answered on 14 Nov 2010, 12:05 AM
Hi. No problem. Please remember to mark as answer if you find this works for you so others can find the solution too. All the best Richard
Tags
Treeview
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Answers by
Richard Slade
Top achievements
Rank 2
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Share this question
or