Linear list to tree node, linear Tree node

Source: Internet
Author: User

Linear list to tree node, linear Tree node

There are the following list of data:

0-PRODUCT
1-1012000178
2-1012610976
3-1016000022
3-1016010178
4-1061000015
5-1062000002
5-1062000002
6-1062000002
7-1062000002
8-1013502230
9-1061010180
10-1062000002
11-1062000002
4-1061010180
4-1062000002
4-1062000002
2-1013502229
3-1061010180
3-1062000002
3-1062000002
4-1061000015
5-1062000002
5-1062000002
6-1062000002
7-1062000002
8-1013502230
9-1061010180
10-1062000002
11-1062000002
2-1013502230
3-1061010180
3-1062000002
3-1062000002
2-1013502231
3-1061010180
3-1062000002
3-1062000002
2-1013502232
3-1061000059
3-1061010180
3-1062000013
3-1062000013
2-1013502233
3-1061000059
3-1061010180
3-1062000013
3-1062000013
2-1013515923
3-1013502234
4-1061000015
4-1061010180
4-1062000002
4-1062000002
3-1013502235
4-1061010180
4-1062000002
4-1062000002
2-1016010130
1-1012101332
2-1016506656
2-1016550476
2-1014060198
3-1016020078

 

1 private void Debug0 (List <LayerRelation> list) 2 {3 int num =-1; 4 TreeNode nowNode = null; 5 TreeNode node = null; 6 treeView1.Nodes. clear (); 7 for (int I = 0; I <list. count; I ++) 8 {9 var model = list [I]; 10 node = new TreeNode (string. format ("{0}-{1}", model. layerNum, model. materielCode); 11 if (model. layerNum = 0) 12 {13 treeView1.Nodes. add (node); 14} 15 else if (model. layerNum-1 = num) 16 {17 nowNode. nodes. add (node); 18} 19 else if (model. layerNum = num) 20 {21 nowNode. parent. nodes. add (node); 22} 23 else if (model. layerNum + 1 = num) 24 {25 TreeNode parentNode = null; 26 for (int n = 0; n <model. layerNum; n ++) 27 {28 parentNode = null? NowNode. parent: parentNode. parent; 29 if (parentNode. level = model. layerNum) 30 {31 parentNode. parent. nodes. add (node); 32 num = node. level; 33 nowNode = node; 34 parentNode = null; 35 break; 36} 37} 38 39 if (parentNode! = Null) 40 {41 parentNode. nodes. add (node); 42 num = node. level; 43 nowNode = node; 44} 45} 46 else47 {48 TreeNode topNode = null; 49 for (int n = 0; n <= (num-model. layerNum); n ++) 50 {51 topNode = null? NowNode. Parent: topNode. Parent; 52} 53 54 if (topNode! = Null) 55 {56 topNode. nodes. add (node); 57 num = node. level; 58 nowNode = node; 59} 60} 61 62 num = node. level; 63 nowNode = node; 64} 65}View Code

Related Article

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.