Ejemplo n.º 1
0
        /// <summary>
        /// 节点互斥同步
        /// 说明
        /// eg:
        ///TreeListNode _node = e.Node;
        ///_node.SyncMutexNodeCheckState(_node.CheckState, n => n.GetNodeType() == NodeType.Cab);
        /// </summary>
        /// <param name="node">需要互斥同步的节点</param>
        /// <param name="checkState">节点状态</param>
        /// <param name="checkHanlder">互斥条件【委托】</param>
        public static void SyncMutexNodeCheckState(this TreeListNode node, CheckState checkState, Predicate <TreeListNode> checkHanlder)
        {
            TreeList _tree = node.TreeList;

            if (checkHanlder(node))//当前节点符合互斥条件时候
            {
                _tree.DownRecursiveTree(n => n.CheckState = CheckState.Unchecked);
            }
            else
            {
                TreeListNode _curParentNode = node.GetParentNode(checkHanlder);//获取符合互斥条件的父节点
                if (_curParentNode == null)
                {
                    return;
                }
                TreeListNode _thePubleNode = node.GetPublicParentNode(checkHanlder);//获取符合互斥条件的公共父节点
                if (_thePubleNode == null)
                {
                    return;
                }
                foreach (TreeListNode n in _thePubleNode.Nodes)
                {
                    foreach (TreeListNode nc in n.Nodes)
                    {
                        if (nc != _curParentNode)
                        {
                            nc.CheckState = CheckState.Unchecked;
                            nc.DownRecursiveNode(nr => nr.CheckState = CheckState.Unchecked);
                        }
                    }
                }
            }
            node.SyncNodeCheckState(checkState);
            node.CheckState = checkState;
        }