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