递归加载Treeview
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 递归城市实例
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
LoadData(treeView1.Nodes, GetArea(0));
}
private void LoadData(TreeNodeCollection treeNodeCollection, List<T_Area> list)
{
foreach (T_Area item in list)
{
TreeNode node = treeNodeCollection.Add(item.AreaName);
node.Tag = item.AreaId;
LoadData(node.Nodes, GetArea(item.AreaId));
}
}
//加载父类省
public List<T_Area> GetArea(int pid)
{
List<T_Area> list=new List<T_Area>();
string sql = "select AreaId,AreaName from T_Area where AreaPid = @pid";
using (SqlDataReader reader= SqlHelper.ExecuteReader(sql,CommandType.Text, new SqlParameter(parameterName:"@pid", value:pid)))
{
if (reader.HasRows)
{
while (reader.Read())
{
T_Area model = new T_Area();
model.AreaId = reader.GetInt32(0);
model.AreaName = reader.GetString(1);
list.Add(model);
}
}
}
return list;
}
}
}
递归加载Treeview的更多相关文章
- WinForm 进程、线程、TreeView递归加载、发送邮件--2016年12月13日
进程:一个程序就是一个进程,但是也有一个程序需要多个进程来支持的情况 进程要使用的类是:Process它在命名空间:System.Diagnostics; 静态方法Start(); Process.S ...
- winform进程、线程、TreeView递归加载
进程: 一般来说,一个程序就是一个进程,不过也有一个程序需要多个进程支持的情况. 进程所使用的类:Process 所需命名空间:System.Diagnostics; 可以通过进行来开启计算机上现有的 ...
- 省市数据递归加载到TreeView
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 将Xml文件递归加载到TreeView中
#region [通过XDocument的方式将Xml文件递归到TreeView控件中] //读取Xml文件(XDocument) //1.加载Xml文件 XDocument document=XD ...
- C# IO操作(五)文件的递归加载
本篇是一个案例,其核心通过代码展示代码中的递归这个用法,程序的界面如下:
- treeview递归加载
实体类: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ...
- WinForm TreeView递归加载
这个其实通俗一点讲就是的树状分支图 首先利用递归添加数据 数据放入 treeView1.Nodes.Add() 中 public Form3() { InitializeComponent(); Tr ...
- Delphi中动态加载TreeView信息
unit Unit3; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- C#递归加载目录树
/// 获取目录管理信息集合 /// </summary> /// <returns></returns> public List<CatalogTree&g ...
随机推荐
- 【Idea】IntelliJ不停地updating indices的解决办法
- prometheus告警插件-alertmanager
prometheus本身不支持告警功能,主要通过插件alertmanage来实现告警.AlertManager用于接收Prometheus发送的告警并对于告警进行一系列的处理后发送给指定的用户. pr ...
- 敏捷开发——User Story
敏捷开发流程: 1.我们首先需要确定一个Product Backlog(按优先顺序排列的一个产品需求列表),这个是由Product Owner 负责的: 2.Scrum Team根据Product B ...
- 理解Object.defineProperty函数中的get与set
defineProperty是什么: 该函数可以直接在一个对象上定义一个新属性,或者修改一个对象的现有属性, 并返回这个对象.通俗理解就是: 给对象添加一个新的属性,或者针对对象里的某些属性,可以给这 ...
- 初识ldap
什么是LDAP? LDAP的英文全称是Lightweight Directory Access Protocol,一般都简称为LDAP.它是基于X.500标准的, 但是简单多了并且可以根据需要定制.与 ...
- 使用fastcall 代替汇编hook thiscall
利用fastcall中ecx edx传递的特性,解决了ecx需要内嵌汇编才能实现hook thiscall函数的问题. #include <stdio.h> #include <st ...
- Fatal error: Uncaught Error: Call to undefined function curl_init()
系统:win7 对于此错误首先检查php_curl扩展是否开启 , extension=curl #注意去掉前面的分号 然后检查php\ext下是否有php_curl.dll 文件(默认都有) ph ...
- Linux下通过vi修改只读文件
打开一个只读文件 $ vi /etc/crontab 此时会进入crontab的编辑界面,通过按键 ESC 可以进入命令模式,按键 I 进入插入模式 但是!如果此时没有权限进行修改的话,虽然可以插入编 ...
- Cognos集成至portal平台运行报表时只出“#”
1. 问题描述 报表集成到平台后,运行报表过程中,当多次运行后,页面只显示“#” 2. 问题分析 这是因为浏览器筛选器限制问题 3. 解决方案 在IE浏览器设置中,Internet选项-安全-自定义级 ...
- Mac下如何配置环境变量JDK
1.在英文输入法的状态下,按键盘“Ctrl + 空格”组合键,调出Spotlight搜索,在这里可以快速启动终端,输入ter,然后回车,即可打开终端: 2.如果你是第一次配置环境变量,可以使用“tou ...