CheckedChanged\Changing not firing

4 posts, 1 answers
  1. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 12 Nov 2010 Link to this post

    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);
        }
    }
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 12 Nov 2010 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 13 Nov 2010 Link to this post

    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 :)
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 13 Nov 2010 Link to this post

    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
Back to Top