zoukankan      html  css  js  c++  java
  • WinForm TreeView递归加载

    这个其实通俗一点讲就是的树状分支图

    首先利用递归添加数据

    数据放入 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);
                }
            }
    
        }
  • 相关阅读:
    CF1416D Graph and Queries
    Wordpress建站系统相关
    微观经济学
    Preface
    Thread pool in chromium
    [fllutter engine] 并发消息队列
    bugku misc
    python 3.1学习
    HTML&CSS
    DOM技术点
  • 原文地址:https://www.cnblogs.com/jiuban2391/p/6188385.html
Copyright © 2011-2022 走看看