Using recursion to implement tree-type node loading in provincial urban areas

Source: Internet
Author: User

List<model. areas> list =NULL;//Defining a areas entity class object for accepting data, recursion is the method call method itself, so you need to define the method, and then the form loads when the method is called, so it needs to be defined as a global variable outside the method body        Private voidFrmareas_load (Objectsender, EventArgs e) {BLL. Areasmanager Bllarea=NewBLL.            Areasmanager (); List=bllarea.bllareas ();//Accept DataLoadData (0,NULL);//call the method, starting with 0, then recursively in the method, until the end of the loop        }        voidLoadData (intAid,treenode parentnode)//define methods, define start parameters and node parameters        {            foreach(MODEL. Areas iteminchList//traversing the accepted areas entity object Data            {                if(item. Apid==aid)//if the Apid property of the areas object = parameter aid{TreeNode node=NewTreeNode (item. AName);//The TreeNode node is instantiated and its constructor is calledNode. Tag = Item;//storing areas entity objects in the tag tag                    if(parentnode==NULL)//If there is no node, the first node of the control (the root node){tvlist.   Nodes.Add (node); //The root node is added to the tree control.                    }                    Else{PARENTNODE.NODES.ADD (node); //Otherwise, add child nodes below the node} loaddata (item. AID, node); //call the method itself, loop to add child nodes                }            }        }

Using recursion to implement tree-type node loading in provincial urban areas

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.