递归加载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 ...
随机推荐
- Spring MVC 返回Json数据环境记录
Spring 版本 Spring4.3.18 Json包 jackson-annotations-2.9.8.jar jackson-core-2.9.8.jar jackson ...
- linux debug tools
linux modules: IO schedule.VFS.OOM.memory.net.process schedule kernel debug: perf(IO bound\CPU bound ...
- 5种网络IO模型
5种网络IO模型(有图,很清楚) 同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非阻塞(non-blocking)IO分别是什么,到 ...
- cron定时任务
1.确认系统安装了cron rpm -aq | grep crontabs 2.认识cron时间格式 3.生成定时任务 crontab -e #进入任务命令编辑模式 30 7,12,20 * * * ...
- Linux 配置ssh 免密码登录
在平常应用中,我们经常会登录到其他主机,比如说服务器,每次都需要用户名和密码. 我们可以通过ssh免密码登录服务器而不需要输入密码. 现在有一台ubuntu的阿里云服务器,称之为 server. 公 ...
- [转]关于Megatops BinCalc RPN计算器的说明
最近收到几个好心人发来的邮件,指出我的BinCalc存在低级BUG,即1+1算出来不等于2--鉴于存在这种误解的人之多,俺不得不爬出来澄清一下--我的Megatops BinCalc当中的计算器是RP ...
- PAT 1128 N Queens Puzzle
1128 N Queens Puzzle (20 分) The "eight queens puzzle" is the problem of placing eight ch ...
- 学习PYTHON之路, DAY 9 - Socket网络编程
__import__ 两种方法,官方推荐下面的方法 Socket 参数介绍 sk.bind(address) 必会 s.bind(address) 将套接字绑定到地址.address地址的格式取决于地 ...
- Code Reading: ORB-SLAM回环检测源码阅读+注释
之前研究过一些回环检测的内容,首先要看的自然是用词袋回环的鼻祖和正当继承人(没有冒犯VINS和LDSO的意思)ORB-SLAM.下面是我的代码注释.因为代码都是自己手打的,不是在源码上注释的,所以一些 ...
- c语言五子棋
#include <stdio.h>#include <stdlib.h>#include <windows.h>#include <conio.h> ...