. NET Common Tricks _ Tree Control tool classes

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Collections;usingDevcomponents.advtree;namespacemyutility {/// <summary>    ///Tree Control Tool class/// </summary>     Public classTreetool {ArrayList Selectarray=NewArrayList (); List<Node> list =NewList<node>(); /// <summary>        ///Select the parent node, and all of its child nodes are also selected/// </summary>        /// <param name= "parentnode" ></param>         PublicArrayList setchildchecked (Node parentnode,arraylist list) { for(inti =0; i<parentnode.nodes.count;i++) {node node=Parentnode.nodes[i]; Node. Checked=true; //list. ADD (node);                if(node. HasChildNodes) {List=setchildchecked (node, list); } Else{list.                ADD (node); }            }            returnlist; }        /// <summary>        ///Select a neutron node whose parent node is also selected/// </summary>        /// <param name= "Childnode" ></param>         Public voidsetparentchecked (Node childnode) {if(Childnode.parent! =NULL) {childNode.Parent.Checked=true;            Setparentchecked (childnode.parent); }        }        /// <summary>        ///cancels a child node and its parent node is also canceled/// </summary>        /// <param name= "Childnode" ></param>         Public voidsetparentunchecked (Node childnode) {if(Childnode.parent! =NULL) {childNode.Parent.Checked=false;            Setparentunchecked (childnode.parent); }        }        /// <summary>        ///cancels the parent node, and all its child nodes are also canceled/// </summary>        /// <param name= "parentnode" ></param>         PublicArrayList cancelchildchecked (Node parentnode, ArrayList list) { for(intI=0; i<parentnode.nodes.count;i++) {node node=Parentnode.nodes[i]; Node. Checked=false; List.                Remove (node); if(node. HasChildNodes) {List=cancelchildchecked (node, list); }            }            returnlist; }        /// <summary>        ///find nodes by name Blur/// </summary>        /// <param name= "Node" >root node</param>        /// <param name= "text" >name</param>        /// /// <param name= "text" >Lookup type, 0 for finding parent node, 1 for finding child nodes</param>        /// <returns></returns>         PublicList<node> Searchnode (node node, String text,intflag) {                        if(Flag = =0&&node. Text.contains (text)) {list.            ADD (node); } Else if(!node. HasChildNodes &&node. Text.contains (text)) {list.            ADD (node); }                        if(node. HasChildNodes) { for(inti =0; I < node. Nodes.count; i++) {List=Searchnode (node.                Nodes[i], Text,flag); }            }            returnlist; }        /// <summary>        ///find nodes exactly by value/// </summary>        /// <param name= "Node" ></param>        /// <param name= "text" ></param>        /// <returns></returns>         PublicList<node>Searchnode_value (node node, String value) {if(node. Tag.tostring (). Equals (value) &&!node. HasChildNodes) {list.            ADD (node); } Else if(node. HasChildNodes) { for(inti =0; I < node. Nodes.count; i++) {List=Searchnode_value (node.                Nodes[i], value); }            }            returnlist; }        /// <summary>        ///traversing selected nodes/// </summary>        /// <param name= "Node" ></param>        /// <param name= "perlist" ></param>        /// <returns></returns>         PublicArrayList Visitselectnode (node node) {if(!node. HasChildNodes) {if(node. Checked = =true) {Selectarray.add (node); } Else{//Cancel Parent Nodesetparentunchecked (node); }            } Else{node. Checked=true;  for(inti =0; I < node. Nodes.count; i++) {Selectarray=Visitselectnode (node.                                   Nodes[i]); }            }            returnSelectarray; }        /// <summary>        ///traverse the node, and select/// </summary>        /// <param name= "Node" ></param>        /// <param name= "perlist" ></param>        /// <returns></returns>         Public voidVisitnode (node node, ArrayList list) {if(!node. HasChildNodes) {if(list. Count! =0) {                    foreach(String IDinchlist) {                        if(node. Checked = =true) {node. Checked=false; }                        if(node. Tag.tostring (). Equals (ID)) {node. Checked=true;  Break; }                    }                } Else{node. Checked=false; }            } Else {                 for(inti =0; I < node. Nodes.count; i++) {Visitnode (node.                Nodes[i], list); }            }        }            }}

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.