![]()
1 public partial class Form1 : Form
2 {
3 List<China> Chlist = new List<China>();
4 public Form1()
5 {
6 InitializeComponent();
7 Chlist = new ChinaData().Select();
8 TreeNode tn1 = new TreeNode("中国");
9 tn1.Tag = "0001";
10 NodesBind(tn1);
11 treeView1.Nodes.Add(tn1);
12 }
13 public void NodesBind(TreeNode tn)
14 {
15 //lambda 表达式
16 List<China> clist = Chlist.Where(a=>a.ParentAreaCode==tn.Tag.ToString()).ToList();
17 foreach (China c in clist)
18 {
19 TreeNode tnn = new TreeNode(c.AreaName);
20 tnn.Tag =c.AreaCode;
21 NodesBind(tnn);//递归
22 tn.Nodes.Add(tnn);
23 }
24 }
25 }