1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace WindowsFormsApplication1
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         List<NodeInfo> nodeInfoList = new List<NodeInfo>();
  15.  
  16.         public Form1()
  17.         {
  18.             InitializeComponent();            
  19.         }
  20.  
  21.         private void Form1_Load(object sender, EventArgs e)
  22.         {
  23.             Init();
  24.             LoadData(new NodeInfo(Guid.Empty, "", Guid.Empty),null);
  25.         }
  26.  
  27.         public void Init()
  28.         {            
  29.             NodeInfo info1 = new NodeInfo(Guid.NewGuid(),"Node1",Guid.Empty);
  30.             NodeInfo info11 = new NodeInfo(Guid.NewGuid(), "Node11", info1.ID);
  31.             NodeInfo info111 = new NodeInfo(Guid.NewGuid(), "Node111", info11.ID);
  32.  
  33.             NodeInfo info2 = new NodeInfo(Guid.NewGuid(), "Node2", Guid.Empty);
  34.             NodeInfo info21 = new NodeInfo(Guid.NewGuid(), "Node21", info2.ID);
  35.             NodeInfo info22 = new NodeInfo(Guid.NewGuid(), "Node22", info2.ID);
  36.  
  37.             NodeInfo info3 = new NodeInfo(Guid.NewGuid(), "Node3", Guid.Empty);
  38.             NodeInfo info31 = new NodeInfo(Guid.NewGuid(), "Node31", info3.ID);
  39.             NodeInfo info311 = new NodeInfo(Guid.NewGuid(), "Node311", info31.ID);
  40.  
  41.             nodeInfoList.Add(info1);
  42.             nodeInfoList.Add(info11);
  43.             nodeInfoList.Add(info111);
  44.             nodeInfoList.Add(info2);
  45.             nodeInfoList.Add(info21);
  46.             nodeInfoList.Add(info22);
  47.             nodeInfoList.Add(info3);
  48.             nodeInfoList.Add(info31);
  49.             nodeInfoList.Add(info311);
  50.         }
  51.  
  52.         public void LoadData(NodeInfo nodeInfo,TreeNode parentNode)
  53.         {
  54.             List<NodeInfo> list =new List<NodeInfo>();
  55.             
  56.             list = GetChildrenList(nodeInfo);
  57.             if (list == null || list.Count == )
  58.             {
  59.                 return;
  60.             }
  61.  
  62.             foreach (NodeInfo info in list)
  63.             {
  64.                 if (info.ParentID == nodeInfo.ID)
  65.                 {
  66.                     TreeNode node = new TreeNode(info.Name);
  67.                     node.Tag = info;
  68.                     if (info.ParentID == Guid.Empty)
  69.                     {
  70.                         treeView1.Nodes.Add(node);
  71.                     }
  72.                     else
  73.                     {
  74.                         parentNode.Nodes.Add(node);
  75.                     }
  76.                     LoadData(info, node);
  77.                 }
  78.             }
  79.         }
  80.  
  81.         private List<NodeInfo> GetChildrenList(NodeInfo nodeInfo)
  82.         {
  83.             List<NodeInfo> list = new List<NodeInfo>();
  84.             list = nodeInfoList.FindAll(=> o.ParentID == nodeInfo.ID);
  85.             return list;
  86.         }
  87.     }
  88.  
  89.     public class NodeInfo
  90.     {
  91.         public Guid ID { get; set; }
  92.         public string Name { get; set; }
  93.         public Guid ParentID { get; set; }
  94.  
  95.         public NodeInfo(Guid id, string name, Guid parentId)
  96.         {
  97.             this.ID = id;
  98.             this.Name = name;
  99.             this.ParentID = parentId;
  100.         }
  101.     }
  102. }

TreeView绑定的更多相关文章

  1. winform treeview 绑定文件夹和文件

    转载:http://www.cnblogs.com/zhbsh/archive/2011/05/26/2057733.html #region treeview 绑定文件夹和文件 /// <su ...

  2. winform treeview绑定数据 DOM操作

    form1 public void treeView() { // datatable 定义变量接收 传归来的值 DataTable Father = new BuMenDA().ConSql(); ...

  3. WPF TreeView绑定字典集合

    <TreeView Name="Tree" HorizontalAlignment="Left" Height="269" Width ...

  4. WPF:TreeView绑定

    namespace PostViewer { using System.Collections.ObjectModel; using System.ComponentModel; /// <su ...

  5. WPF TreeView绑定xaml的写法

    方法一 <Window x:Class="TreeViewDemo.MainWindow" xmlns="http://schemas.microsoft.com/ ...

  6. C# treeview 绑定数据 【转】

    private void bindTreeView1() { string sql = "select * from dm_category"; DataTable dt = db ...

  7. TreeView绑定无限层级关系类

    protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Bind_TV(TreeView1.Nodes); ...

  8. C# 中的treeview绑定数据库(递归算法)

    近日面试的给我两道题目,一道是IQ测试,第二个就是题目所言 总共两个表 department(id int not null primary key,parentid int,name char(50 ...

  9. C# treeview绑定

    protected void Page_Load(object sender, EventArgs e)        {            if (!IsPostBack)            ...

随机推荐

  1. 《DSP using MATLAB》示例Example 8.11

    %% ------------------------------------------------------------------------ %% Output Info about thi ...

  2. flask第十七篇——模板【1】

    从这一节开始我们就正式进入flask一个重要的模块——模板了. 我们平时看的知乎平台就是Python开发的,可以看到他的很多页面布局都是一样的,比如你现在搜“如何自学Python”,去知乎看他的页面是 ...

  3. 【angularJS】Filter 过滤器

    当从后台获取到的数据呈现到视图上时,此时可能需要对数据进行相应的转换,此时我们可以通过过滤器在不同页面进行不同数据的格式抓换,在AngularJS中有常见默认的过滤器,当然若不满足所需,我们可以自定义 ...

  4. LeetCode 424. Longest Repeating Character Replacement

    原题链接在这里:https://leetcode.com/problems/longest-repeating-character-replacement/description/ 题目: Given ...

  5. MkDocs 搭建试用

    http://www.mkdocs.org/备注:    在平时的开发中文档管理是一个比较重要的部分,同时集成在 平时开发的持续集成中,可以加速开发   1. 安装 pip install mkdoc ...

  6. 数据库的备份与恢复(oracle 11g) (转)

    一.       内容与步骤 (注意这里许多步骤需要同学们查资料,理解并消化后才能完成) 1.数据库创建 (1)   安装Oralce11g: (2)   创建至少两个以上用户: (3)   每个用户 ...

  7. app.js:1274 [Vue warn]: Error in render: "TypeError: Cannot read property 'object_id' of undefined"问题小记

    凌晨遇到一个控制台报错的信息,总是显示有对象中的元素未定义 明明是有把定义对象的值的,后面发现是把没有返回值的函数又赋值一遍给未定义的元素所属的对象,

  8. CRC 自动判断大端 小端

    /* aos_crc64.c -- compute CRC-64 * Copyright (C) 2013 Mark Adler * Version 1.4 16 Dec 2013 Mark Adle ...

  9. SharedPreference工具类

    public class SPUtils { /** * 保存在手机里的SP文件名 */ public static final String FILE_NAME = "my_sp" ...

  10. android 文件上传,中文utf-8编码

    要上传文件到后台的php服务器,服务器能收到中文,手机发送过去,却只能收到一堆转了UTF-8的编码(就是要decode后才是中文的编码).android这边上传文件通常是用stream方式上传的,用M ...