Completed
Last Updated: 11 Apr 2016 07:44 by ADMIN
ADMIN
Georgi I. Georgiev
Created on: 05 Sep 2013 06:28
Category: TreeView
Type: Bug Report
1
FIX. RadTreeView - manually setting toggled state results in invalid visual state
To reproduce:
Add a RadTreeView ,add nodes, enable TriState, disable AutoCheckChildNodes and use this code:
void cxTreeView2_NodeCheckedChanging(object sender, RadTreeViewCancelEventArgs e)
{
    if (!cxTreeView2.AutoCheckChildNodes && cxTreeView2.CheckBoxes && cxTreeView2.TriStateMode)
    {
        cxTreeView2.TreeViewElement.NodeCheckedChanging -= cxTreeView2_NodeCheckedChanging;
        if (e.Node.CheckState == ToggleState.Indeterminate)
        {
            e.Cancel = true;
            e.Node.CheckState = ToggleState.On;
            CheckAllChildren(e.Node);
        }

        cxTreeView2.TreeViewElement.NodeCheckedChanging += cxTreeView2_NodeCheckedChanging;
    }
}

void CheckAllChildren(RadTreeNode parent)
{
    foreach (var node in parent.Nodes)
    {
        node.CheckState = ToggleState.On;
        CheckAllChildren(node);
    }
}

Click a top node two times and remove the mouse from the checkbox, it is now showing as Indetermined but the data item is on.

Workaround:
void cxTreeView2_NodeCheckedChanging(object sender, RadTreeViewCancelEventArgs e)
{
    if (!cxTreeView2.AutoCheckChildNodes && cxTreeView2.CheckBoxes && cxTreeView2.TriStateMode)
    {
        cxTreeView2.TreeViewElement.NodeCheckedChanging -= cxTreeView2_NodeCheckedChanging;
        if (e.Node.CheckState == ToggleState.Indeterminate)
        {
            e.Cancel = true;
            e.Node.CheckState = ToggleState.On;
            CheckAllChildren(e.Node);

            cxTreeView2.TreeViewElement.Update(RadTreeViewElement.UpdateActions.Reset);

        }

        cxTreeView2.TreeViewElement.NodeCheckedChanging += cxTreeView2_NodeCheckedChanging;
    }
}

void CheckAllChildren(RadTreeNode parent)
{
    foreach (var node in parent.Nodes)
    {
        node.CheckState = ToggleState.On;
        CheckAllChildren(node);
    }
}
0 comments