标签:add 关联 bsp lis img images orm class http
这个其实通俗一点讲就是的树状分支图
首先利用递归添加数据
数据放入 treeView1.Nodes.Add() 中
public Form3() { InitializeComponent(); TreeNode t1 = new TreeNode("中国"); TreeNode t2 = new TreeNode("北京"); TreeNode t3 = new TreeNode("朝阳区"); t2.Nodes.Add(t3); t1.Nodes.Add(t2); treeView1.Nodes.Add(t1); }
然后再用tag 与对象关联的用户定义数据
public partial class Form3 : Form { List<China> alllist = new List<China>(); public Form3() { InitializeComponent(); alllist = new ChinaData().Select(); TreeNode tn1 = new TreeNode("中国"); tn1.Tag = "0001"; NodesBind(tn1); treeView1.Nodes.Add(tn1); } public void NodesBind(TreeNode tn) { List<China> clist = alllist.Where(r => r.ParentAreaCode == tn.Tag.ToString()).ToList(); foreach (China c in clist) { TreeNode tnn = new TreeNode(c.AreaName); tnn.Tag = c.AreaCode; //递归 NodesBind(tnn); tn.Nodes.Add(tnn); } } }
标签:add 关联 bsp lis img images orm class http
原文地址:http://www.cnblogs.com/jiuban2391/p/6188385.html