Key code:
/// <Summary> /// check the status of synchronization Parent and Child Nodes /// description /// use the code in the AfterCheckNode event /// eg: e. node. syncNodeCheckState (e. node. checkState ); /// </summary> /// <param name = "node"> node to be synchronized </param> /// <param name = "check"> the node is currently selected status </param> public static void SyncNodeCheckState (this TreeListNode node, checkState check) {SyncNodeCheckState_Child (node, check); SyncNodeCheckState_Parent (node, check);} private static void SyncNodeChe CkState_Child (TreeListNode node, CheckState check) {if (node! = Null) {node. DownRecursiveNode (n => n. CheckState = check);} private static void SyncNodeCheckState_Parent (TreeListNode node, CheckState check) {if (node. ParentNode! = Null) {bool _ cked = false; CheckState _ ckState; foreach (TreeListNode cn in node. ParentNode. Nodes) {_ ckState = cn. CheckState; if (check! = _ CkState) {_ cked =! _ Cked; break ;}} node. ParentNode. CheckState = _ cked? CheckState. Indeterminate: check; SyncNodeCheckState_Parent (node. ParentNode, check );}}
/// <Summary> /// recursion down the TreeListNode node /// </summary> /// <param name = "node"> the node to be recursion down </param> /// <param name = "conditionHanlder"> DeleGate </param> public static void DownRecursiveNode (this TreeListNode node, action <TreeListNode> conditionHanlder) {foreach (TreeListNode _ childNode in node. nodes) {conditionHanlder (_ childNode); DownRecursiveNode (_ childNode, conditionHanlder );}}
Code effect: