treeview递归加载
实体类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace WindowsFormsApplication2
{
public class China
{
public string AreaCode { get; set; }
public string AreaName { get; set; }
public string ParentAreaCode { get; set; } }
}
数据访问类:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text; namespace WindowsFormsApplication2
{
public class ChinaData
{
SqlConnection conn = null;
SqlCommand cmd = null; public ChinaData()
{
conn = new SqlConnection("server=.;database=mydb;user=sa;pwd=123");
cmd = conn.CreateCommand();
} public List<China> Select(string pcode)
{
List<China> clist = new List<China>(); cmd.CommandText = "select *from ChinaStates where ParentAreaCode = '" + pcode + "'"; conn.Open();
SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows)
{
while (dr.Read())
{
China c = new China();
c.AreaCode = dr[].ToString();
c.AreaName = dr[].ToString();
c.ParentAreaCode = dr[].ToString(); clist.Add(c);
}
} conn.Close();
return clist;
} public List<China> Select()
{
List<China> clist = new List<China>(); cmd.CommandText = "select *from ChinaStates"; conn.Open();
SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows)
{
while (dr.Read())
{
China c = new China();
c.AreaCode = dr[].ToString();
c.AreaName = dr[].ToString();
c.ParentAreaCode = dr[].ToString(); clist.Add(c);
}
} conn.Close();
return clist;
} }
}
form1:treeview 使用递归
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
List<China> AllList = new List<China>(); public Form1()
{
InitializeComponent(); AllList = new ChinaData().Select(); TreeNode tn1 = new TreeNode("中国");
tn1.Tag = ""; NodesBind(tn1); treeView1.Nodes.Add(tn1); } public void NodesBind(TreeNode tn)
{
//lambda 表达式
List<China> clist = AllList.Where(r => r.ParentAreaCode == tn.Tag.ToString()).ToList(); foreach (China c in clist)
{
TreeNode tnn = new TreeNode(c.AreaName);
tnn.Tag = c.AreaCode; NodesBind(tnn); tn.Nodes.Add(tnn);
}
} }
}
treeview递归加载的更多相关文章
- WinForm 进程、线程、TreeView递归加载、发送邮件--2016年12月13日
进程:一个程序就是一个进程,但是也有一个程序需要多个进程来支持的情况 进程要使用的类是:Process它在命名空间:System.Diagnostics; 静态方法Start(); Process.S ...
- winform进程、线程、TreeView递归加载
进程: 一般来说,一个程序就是一个进程,不过也有一个程序需要多个进程支持的情况. 进程所使用的类:Process 所需命名空间:System.Diagnostics; 可以通过进行来开启计算机上现有的 ...
- WinForm TreeView递归加载
这个其实通俗一点讲就是的树状分支图 首先利用递归添加数据 数据放入 treeView1.Nodes.Add() 中 public Form3() { InitializeComponent(); Tr ...
- 省市数据递归加载到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.ComponentModel;using System.Data;using Sy ...
- 仿Windows制作TreeView数据加载
时间有限就直接贴源码吧,理解思路即可. 页面代码: <asp:TreeView ID="TreeViewLeft" runat="server" Show ...
- asp.net treeview 异步加载
在使用TreeView控件的时候,如果数据量太大,这个TreeView控件加载会很慢,有时甚至加载失败, 为了更好的使用TreeView控件加载大量的数据,采用异步延迟加载TreeView. 在Tre ...
随机推荐
- 移除\禁用 jquery mobile 元素样式渲染
在元素上加属性. data-role="none"
- SynchronousQueue 的简单应用
SynchronousQueue是这样一种阻塞队列,其中每个 put 必须等待一个 take,反之亦然.同步队列没有任何内部容量,甚至连一个队列的容量都没有. 不能在同步队列上进行 peek ...
- TF-IDF 文本相似度分析
前阵子做了一些IT opreation analysis的research,从产线上取了一些J2EE server运行状态的数据(CPU,Menory...),打算通过训练JVM的数据来建立分类模型, ...
- 升级到Xcode6.2后 免证书真机调试出错的问题
我的本来是Xcode6.1 可以正常免证书真机调试,升级到Xcode6.2以后,真机调试就报错,然后就又按照这篇文章http://www.cnblogs.com/liuliuliu/p/4030524 ...
- 【转】OpenStack奥斯汀峰会Keynotes国内抢先看
http://www.openstack.cn/?p=5341 OpenStack奥斯汀峰会Keynotes国内抢先看入口:http://www.tudou.com/home/_903780397/i ...
- PHP输出当前进程所有变量 / 常量 / 模块 / 函数 / 类
<?php /* 不知道怎么打印某个函数的参数和相关分类类型的所有函数 以下函数如果没有参数,返回的都是一个数组get_defined_functions() 获取所有已经定义的函数get_de ...
- Comet 反Ajax: jQuery与PHP实现Ajax长轮询
原文地址(http://justcode.ikeepstudying.com/2016/08/comet-%E5%8F%8Dajax-%E5%9F%BA%E4%BA%8Ejquery%E4%B8%8E ...
- jquery validate 自定义验证方法
query validate有很多验证规则,但是更多的时候,需要根据特定的情况进行自定义验证规则. 这里就来聊一聊jquery validate的自定义验证. jquery validate有一个方法 ...
- html drag 拖拽用法和注意事项
1.拖拽过程中的事件暂时jQuery里还没有,只能通过html DOM 来进行绑定,不然无法获取dataTransfer对象 2.在dragstart .dragover 等事件中可以用 evt.pr ...
- phpcms V9 数据模型基类
在学习<phpcms V9首页模板文件解析>的第七步,我们看到content_model类,文件路径:phpcms/model/content_model.class.php 从代码中,可 ...