[WinForm] [DevExpress] [TreeList] synchronization of CheckState status on Parent and Child Nodes

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.