递归加载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 ...
随机推荐
- inconfont的使用
iconfont 进入阿里的矢量图标库,进入到我的项目(图标库)中,可以看到如下页面 根据不同的使用方式(Unicode.Font class.Symbol)可将对应文件下载至本地或直接在项目中引入 ...
- ECharts前端图形展示
这次负责慢查询预警,前后端都是自己处理,这次遇到了前端作图的需求,做一个记录以便后续使用: 使用的作图方式是ECharts,相应的example官方有相应的文档和使用方法,比较简单,一下只贴链接: h ...
- 在ibatis中时间段查询完整代码
ibatis.xml文件中的代码如下: <typeAlias alias="ServInvokeTest" type="com.entity.ServInvokeT ...
- 【Linux】gdb调试
g++ -g ... gdb l 列出代码,回车键继续 break main / 行号 加断点 n 单步运行 s 单步运行(可进入函数) p 输出变量 p *array@len ...
- 2018 HDU多校第三场赛后补题
2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...
- Introduction of Servlet Filter(介绍javaweb组件之一过滤器filter)
javaweb的三大组件都需要交给web服务器运行,都需要在web.xml文件中配置. ①Servlet:javax.servlet.Servlet通过http协议接受客户端的请求,并作出响应的Jav ...
- laravel的测试工具debug安装:
在项目根目录执行: composer require barryvdh/laravel-debugbar --dev
- linux常用命令 命令管道符
多命令顺序执行 多命令顺序执行 多命令执行符 格式 作用 : 命令1:命令2 多个命令顺序执行,命令之间没有任何逻辑联系 && 命令1&&命令2 逻辑与 当命令1正确执 ...
- Linux c获取任意路径的硬盘使用情况
没有什么好说的,其实就是获取硬盘的statfs信息结构 代码如下: #include <stdio.h> #include <stdlib.h> #include <sy ...
- Centos 配置mailx使用外部smtp发送邮件
安装mailx yum install mailx 配置mailx 笔者推荐163邮箱,当然,QQ邮箱也是可以的,PS:记得要进邮箱打开SMTP vi /etc/mail.rc //如果不存在,则编辑 ...