递归加载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 ...
随机推荐
- 队列添加对象后,所有都变成相同的(bug)
代码背景: 定义全局变量 private object currentObj=new object(); ;i<objectList.count;i++) { currentObj=object ...
- request.getParameter()在get和post方法中文乱码问题
乱码原因:Http请求传输时将url以ISO-8859-1编码,服务器收到字节流后默认会以ISO-8859-1编码来解码成字符流(造成中文乱码) post请求: 假设提交请求的jsp页面是UTF-8编 ...
- PlantUML + Chrome 联合使用
之前都是本地下载安装一个PlantUML,安装过程有点复杂,涉及到的其他插件也有些多. 后面发现Chrome浏览器上提供了相关插件,整个过程简直太流畅了.记录下. 安装: 打开Chrome的线上应用商 ...
- qt程序编译错误:could not exec ‘/usr/lib/x86_64-linux-gnu/qt4/bin/qmake’
linux下安装Qt5.7后添加qmake环境变量后出现错误 执行: qmake -v 出现错误:qmake: could not exec ‘/usr/lib/x86_64-linux-gnu/qt ...
- 在学习JavaScript中用到的示例
jQuery老师博客 一.定时器示例 功能:让input的文本框,显示时间,并实时更新 逻辑思路: 1.先定义一个函数,用来把当前时间赋值给input.value 2.开始button设置点击事件,并 ...
- 跟随我在oracle学习php(10)
正则表达式 做验证 做匹配 用符号来描述书写规则:/ 中间写正则表达式 /^ :匹配开头,$:匹配结尾 : /^ve/以ve开头的 /ve$/以ve结尾\d:一个任意的数字\w:一个任意的数字或字母\ ...
- sed应用
删除每行空白字符 sed -i 's/^[[:space:]]*//' user.txt 删除空白行 sed -i '/^$/d' user.txt
- Linux c获取任意路径的硬盘使用情况
没有什么好说的,其实就是获取硬盘的statfs信息结构 代码如下: #include <stdio.h> #include <stdlib.h> #include <sy ...
- hosts文件被修改后的惨案
在公司MAC电脑上/etc/hosts中尝试反向解析一个ip到localhost, 即:xxx.xxx.xxx.xxx localhost 然后发现tomcat起不来;
- mybatis源码解析之Configuration加载(四)
概述 上一篇文章,我们主要讲了datasource的相关内容,那么<environments>标签下的内容就看的差不多了,今天就来看一下在拿到transationManager和datas ...