zoukankan      html  css  js  c++  java
  • winform treeView 数据绑定

    转载:http://www.jetwu.cn/archives/737

    winform treeView 数据绑定

     private void Form1_Load(object sender, EventArgs e)
            {
                Types = new List<UrlTypes>()
                {
                    new UrlTypes() {Id = 1, Name = "中国", Value = "0", ParentId = 0},
                    new UrlTypes() {Id = 2, Name = "河南", Value = "0", ParentId = 1},
                    new UrlTypes() {Id = 3, Name = "河北", Value = "0", ParentId = 1},
                    new UrlTypes() {Id = 4, Name = "南阳", Value = "0", ParentId = 2},
                    new UrlTypes() {Id = 4, Name = "信阳", Value = "0", ParentId = 2},
                    new UrlTypes() {Id = 5, Name = "新野", Value = "0", ParentId = 4},
                    new UrlTypes() {Id = 6, Name = "石家庄", Value = "0", ParentId = 3}
                };
     
                var topNode = new TreeNode();
                topNode.Name = "0";
                topNode.Text = "世界";
                treeView1.Nodes.Add(topNode);
                Bind(topNode,Types,0);
                 
                treeView1.ExpandAll();
            }
          private void Bind(TreeNode parNode,List<UrlTypes> list,int nodeId )
            {
                var childList = list.FindAll(t => t.ParentId == nodeId).OrderBy(t=>t.Id);
                foreach (var urlTypese in childList)
                {
                    var node = new TreeNode();
                    node.Name = urlTypese.Id.ToString();
                    node.Text = urlTypese.Name;
                    parNode.Nodes.Add(node);
                    Bind(node,list,urlTypese.Id);
                }
            }
        public class UrlTypes
        {
            public int Id { get; set; }
     
            public string Name { get; set; }
     
            public string Value { get; set; }
     
            public int ParentId { get; set; }
        }
  • 相关阅读:
    2.2.16锁对象的改变
    2.2.15内置类与同步:测试2
    2.2.14内置类与同步:测试1
    2.2.13内置类与静态内置类
    libev客户端
    Linux下sqlite3编程
    ds18b20驱动及应用程序
    ds18b20采集温度并上报服务器
    linux下GPRS模块ppp拨号上网
    linux下GPRS模块的应用程序
  • 原文地址:https://www.cnblogs.com/51net/p/4238126.html
Copyright © 2011-2022 走看看