Loop recursion + return value (treeview example)

Source: Internet
Author: User

Example: Get all node of the TreeView, save to List<treenode>, and encapsulate to the generic tool class:

Method One: Empty the static type list before using the static method, property---Call

1          Public StaticList<treenode> allnodes =NULL;2          Public Static voidgettreeviewallnodes (treenodecollection Nodes)3         {4             foreach(TreeNode nodeinchNodes)5             {6 allnodes.add (node);7                 if(node. Childnodes.count >0)8                 {9 gettreeviewallnodes (node. ChildNodes);Ten                 } One             } A         } -          Public StaticList<treenode>getnodes (TreeView TV) -         { the gettreeviewallnodes (TV. Nodes); -             returnAllnodes; -}
Note: If you use a static type list, you need to empty the list<treenode&gt before calling the generic tool class, otherwise the overlay will appear. In the constructor, empty:
 Public Tools () {      allnodes.clear ();   }

Method Two, use the internal method, the property---call directly

1          PublicList<treenode> allnodes =NewList<treenode>();2          Public voidgettreeviewallnodes (treenodecollection Nodes)3         {4             foreach(TreeNode nodeinchNodes)5             {6 allnodes.add (node);7                 if(node. Childnodes.count >0)8                 {9 gettreeviewallnodes (node. ChildNodes);Ten                 } One             } A         } -          PublicList<treenode>getnodes (TreeView TV) -         { the gettreeviewallnodes (TV. Nodes); -             returnAllnodes; -}

Question: Can you use a method to both iterate and get the return value???

Loop recursion + return value (treeview example)

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.