TreeView绑定
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- List<NodeInfo> nodeInfoList = new List<NodeInfo>();
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- Init();
- LoadData(new NodeInfo(Guid.Empty, "", Guid.Empty),null);
- }
- public void Init()
- {
- NodeInfo info1 = new NodeInfo(Guid.NewGuid(),"Node1",Guid.Empty);
- NodeInfo info11 = new NodeInfo(Guid.NewGuid(), "Node11", info1.ID);
- NodeInfo info111 = new NodeInfo(Guid.NewGuid(), "Node111", info11.ID);
- NodeInfo info2 = new NodeInfo(Guid.NewGuid(), "Node2", Guid.Empty);
- NodeInfo info21 = new NodeInfo(Guid.NewGuid(), "Node21", info2.ID);
- NodeInfo info22 = new NodeInfo(Guid.NewGuid(), "Node22", info2.ID);
- NodeInfo info3 = new NodeInfo(Guid.NewGuid(), "Node3", Guid.Empty);
- NodeInfo info31 = new NodeInfo(Guid.NewGuid(), "Node31", info3.ID);
- NodeInfo info311 = new NodeInfo(Guid.NewGuid(), "Node311", info31.ID);
- nodeInfoList.Add(info1);
- nodeInfoList.Add(info11);
- nodeInfoList.Add(info111);
- nodeInfoList.Add(info2);
- nodeInfoList.Add(info21);
- nodeInfoList.Add(info22);
- nodeInfoList.Add(info3);
- nodeInfoList.Add(info31);
- nodeInfoList.Add(info311);
- }
- public void LoadData(NodeInfo nodeInfo,TreeNode parentNode)
- {
- List<NodeInfo> list =new List<NodeInfo>();
- list = GetChildrenList(nodeInfo);
- if (list == null || list.Count == )
- {
- return;
- }
- foreach (NodeInfo info in list)
- {
- if (info.ParentID == nodeInfo.ID)
- {
- TreeNode node = new TreeNode(info.Name);
- node.Tag = info;
- if (info.ParentID == Guid.Empty)
- {
- treeView1.Nodes.Add(node);
- }
- else
- {
- parentNode.Nodes.Add(node);
- }
- LoadData(info, node);
- }
- }
- }
- private List<NodeInfo> GetChildrenList(NodeInfo nodeInfo)
- {
- List<NodeInfo> list = new List<NodeInfo>();
- list = nodeInfoList.FindAll(o => o.ParentID == nodeInfo.ID);
- return list;
- }
- }
- public class NodeInfo
- {
- public Guid ID { get; set; }
- public string Name { get; set; }
- public Guid ParentID { get; set; }
- public NodeInfo(Guid id, string name, Guid parentId)
- {
- this.ID = id;
- this.Name = name;
- this.ParentID = parentId;
- }
- }
- }
TreeView绑定的更多相关文章
- winform treeview 绑定文件夹和文件
转载:http://www.cnblogs.com/zhbsh/archive/2011/05/26/2057733.html #region treeview 绑定文件夹和文件 /// <su ...
- winform treeview绑定数据 DOM操作
form1 public void treeView() { // datatable 定义变量接收 传归来的值 DataTable Father = new BuMenDA().ConSql(); ...
- WPF TreeView绑定字典集合
<TreeView Name="Tree" HorizontalAlignment="Left" Height="269" Width ...
- WPF:TreeView绑定
namespace PostViewer { using System.Collections.ObjectModel; using System.ComponentModel; /// <su ...
- WPF TreeView绑定xaml的写法
方法一 <Window x:Class="TreeViewDemo.MainWindow" xmlns="http://schemas.microsoft.com/ ...
- C# treeview 绑定数据 【转】
private void bindTreeView1() { string sql = "select * from dm_category"; DataTable dt = db ...
- TreeView绑定无限层级关系类
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Bind_TV(TreeView1.Nodes); ...
- C# 中的treeview绑定数据库(递归算法)
近日面试的给我两道题目,一道是IQ测试,第二个就是题目所言 总共两个表 department(id int not null primary key,parentid int,name char(50 ...
- C# treeview绑定
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) ...
随机推荐
- 《DSP using MATLAB》示例Example 8.11
%% ------------------------------------------------------------------------ %% Output Info about thi ...
- flask第十七篇——模板【1】
从这一节开始我们就正式进入flask一个重要的模块——模板了. 我们平时看的知乎平台就是Python开发的,可以看到他的很多页面布局都是一样的,比如你现在搜“如何自学Python”,去知乎看他的页面是 ...
- 【angularJS】Filter 过滤器
当从后台获取到的数据呈现到视图上时,此时可能需要对数据进行相应的转换,此时我们可以通过过滤器在不同页面进行不同数据的格式抓换,在AngularJS中有常见默认的过滤器,当然若不满足所需,我们可以自定义 ...
- LeetCode 424. Longest Repeating Character Replacement
原题链接在这里:https://leetcode.com/problems/longest-repeating-character-replacement/description/ 题目: Given ...
- MkDocs 搭建试用
http://www.mkdocs.org/备注: 在平时的开发中文档管理是一个比较重要的部分,同时集成在 平时开发的持续集成中,可以加速开发 1. 安装 pip install mkdoc ...
- 数据库的备份与恢复(oracle 11g) (转)
一. 内容与步骤 (注意这里许多步骤需要同学们查资料,理解并消化后才能完成) 1.数据库创建 (1) 安装Oralce11g: (2) 创建至少两个以上用户: (3) 每个用户 ...
- app.js:1274 [Vue warn]: Error in render: "TypeError: Cannot read property 'object_id' of undefined"问题小记
凌晨遇到一个控制台报错的信息,总是显示有对象中的元素未定义 明明是有把定义对象的值的,后面发现是把没有返回值的函数又赋值一遍给未定义的元素所属的对象,
- CRC 自动判断大端 小端
/* aos_crc64.c -- compute CRC-64 * Copyright (C) 2013 Mark Adler * Version 1.4 16 Dec 2013 Mark Adle ...
- SharedPreference工具类
public class SPUtils { /** * 保存在手机里的SP文件名 */ public static final String FILE_NAME = "my_sp" ...
- android 文件上传,中文utf-8编码
要上传文件到后台的php服务器,服务器能收到中文,手机发送过去,却只能收到一堆转了UTF-8的编码(就是要decode后才是中文的编码).android这边上传文件通常是用stream方式上传的,用M ...