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的更多相关文章

  1. WinForm 进程、线程、TreeView递归加载、发送邮件--2016年12月13日

    进程:一个程序就是一个进程,但是也有一个程序需要多个进程来支持的情况 进程要使用的类是:Process它在命名空间:System.Diagnostics; 静态方法Start(); Process.S ...

  2. winform进程、线程、TreeView递归加载

    进程: 一般来说,一个程序就是一个进程,不过也有一个程序需要多个进程支持的情况. 进程所使用的类:Process 所需命名空间:System.Diagnostics; 可以通过进行来开启计算机上现有的 ...

  3. 省市数据递归加载到TreeView

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  4. 将Xml文件递归加载到TreeView中

    #region [通过XDocument的方式将Xml文件递归到TreeView控件中] //读取Xml文件(XDocument) //1.加载Xml文件 XDocument  document=XD ...

  5. C# IO操作(五)文件的递归加载

    本篇是一个案例,其核心通过代码展示代码中的递归这个用法,程序的界面如下:

  6. treeview递归加载

    实体类: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ...

  7. WinForm TreeView递归加载

    这个其实通俗一点讲就是的树状分支图 首先利用递归添加数据 数据放入 treeView1.Nodes.Add() 中 public Form3() { InitializeComponent(); Tr ...

  8. Delphi中动态加载TreeView信息

    unit Unit3; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  9. C#递归加载目录树

    /// 获取目录管理信息集合 /// </summary> /// <returns></returns> public List<CatalogTree&g ...

随机推荐

  1. RESTful Level

    REST(表述性状态转移)是最近几年讨论的最为热烈的话题之一,其起源于Roy.T.Fielding博士的论文<软件架构风格和基于网路的软件架构设计>.Roy博士在他的论文里从架构风格角度阐 ...

  2. Matlab:正则Euler分裂

    函数文件1: function b=F(x0,h,u,tau) b(,)=x0()-u(); b(,)=x0()-u()+*h*1e8*cos(tau)*x0(); 函数文件2: function g ...

  3. ThinkPHP部署在lnmp环境中碰到的问题

    先说一下问题: 因为tp5的入口文件在public目录下,而Application和public同级, 我用的lnmp1.5默认做了防跨站目录设置,所以导致入口文件无法进入application目录, ...

  4. unity中编辑器直接截屏代码

    using UnityEngine; using System.Collections; using System.Windows.Forms; public class screenshots : ...

  5. Property Exercise

    要求一:自定义用户信息数据结构,写入文件,然后读出内容,利用eval重新获取数据结构 3 with open('user.db','w') as write_file:#创建并以写入的方式打开一个文件 ...

  6. node.js http接口调试时请求串行特性分析

    缘起: 产品业务上有个类数据库服务的请求时间比较长(类似mysql的sql查询),为了优化减少并发时的请求数,做了一个并发时共用请求的优化. 通过单元测试后,想通过手动模拟看下效果,发现优化一直不能生 ...

  7. JS 打印实现部分打印

    function Print() { $.ligerDialog.confirm('确定要打印吗?', true, function (yes, value) { if (yes) { var old ...

  8. SQL循环表里的数据

    select * into #t1 from Userinfodeclare @id varchar(2000);while (exists(select ProjectID from #t1))be ...

  9. POJ - 3264——Balanced Lineup(入门线段树)

    Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 68466   Accepted: 31752 ...

  10. css 底层知识点

    (摘自张鑫旭老师的课程内容) position: absolute 1. 定位元素(关闭按钮etc):dom顺序保持正确,然后根据absolute的位置跟随性(脱离文档流但是位置不变)和margin值 ...