this.tlMatrixCategories.AfterCheckNode += new DevExpress.XtraTreeList.NodeEventHandler(this.tlMatrixCategories_AfterCheckNode);

private void treeList_AfterCheckNode( object sender, NodeEventArgs e )
        {
            if( e.Node.CheckState == CheckState.Indeterminate )
                e.Node.CheckState = CheckState.Checked;
            treeList.BeginUpdate();
            try
            {
                SetCheckedChildNodes( e.Node, e.Node.CheckState );
                if( e.Node.ParentNode != null )
                    SetCheckedParentNodes( e.Node.ParentNode, e.Node.CheckState );
            }
            finally
            {
                treeList.EndUpdate();
            }
        }
        private void SetCheckedChildNodes( TreeListNode node, CheckState checkState )
        {
            for( int i = 0; i < node.Nodes.Count; i++ )
            {
                node.Nodes[ i ].CheckState = checkState;
                SetCheckedChildNodes( node.Nodes[ i ], checkState );
            }
        }
        private void SetCheckedParentNodes( TreeListNode node, CheckState checkState )
        {
            bool b = false;
            for( int i = 0; i < node.Nodes.Count; i++ )
            {
                if( !checkState.Equals( node.Nodes[ i ].CheckState ) )
                {
                    b = !b;
                    break;
                }
            }
            node.CheckState = b ? CheckState.Indeterminate : checkState;
            if( node.ParentNode != null )
                SetCheckedParentNodes( node.ParentNode, checkState );
        }

+ Recent posts