Winform中的Treeview动态绑定数据库
http://bbs.csdn.net/topics/370139193
|
1
2
3
4
5
6
|
CREATE TABLE [dbo].[Company] ( [Id] [int] IDENTITY (1, 1) Primary Key NOT NULL , [Levers] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL , [LevelId] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL , [Name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ) |

|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
public partial class Form1 : Form { public string rootId = "-1"; public Form1() { InitializeComponent(); AddRootCompany(rootId); AddSubCompany(); } /// <summary> /// 添加总公司 /// </summary> /// <param name="rootId"></param> private void AddRootCompany(string rootId) { DataSet ds = new DataSet(); using (SqlConnection con = new SqlConnection("Data Source=localhost;uid=sa;pwd=saiyang;Database=CSDN")) { con.Open(); string strSQL = "select * from Company where Levers='" + rootId + "'"; using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, con)) { adapter.Fill(ds); } TreeNode NewNode = new TreeNode(); NewNode.Text = ds.Tables[0].Rows[0]["Name"].ToString().Trim(); this.treeView1.Nodes.Add(NewNode); } } /// <summary> /// 添加子公司 /// </summary> private void AddSubCompany() { DataSet ds = getMenuByLevel(rootId.ToString()); for (int j = 0; j < ds.Tables[0].Rows.Count; j++) { InitTreeCompanyChildNode(treeView1.Nodes[j], ds.Tables[0].Rows[j]["LevelId"].ToString()); } } /// <summary> /// 获取层次级别 /// </summary> /// <param name="getparams"></param> /// <returns></returns> public DataSet getMenuByLevel(string param) { DataSet ds = new DataSet(); using (SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=CSDN;User ID=sa;Password=saiyang")) { con.Open(); string strSQL = "select * from Company where Levers='" + param + "'"; using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, con)) { adapter.Fill(ds); } } return ds; } /// <summary> /// 递归获取子节点 /// </summary> /// <param name="PNode"></param> /// <param name="classParentID"></param> private void InitTreeCompanyChildNode(TreeNode pNode, string classParentID) { DataSet ds = getMenuByLevel(classParentID); DataView dataView = new DataView(); dataView = ds.Tables[0].DefaultView; foreach (DataRowView drv in dataView) { string id = drv["LevelId"].ToString(); string name = drv["Name"].ToString(); TreeNode NewNode = new TreeNode(); //将子公司添加到父节点下面 NewNode.Text = name; pNode.Nodes.Add(NewNode); InitTreeCompanyChildNode(NewNode, id); } } } |

Winform中的Treeview动态绑定数据库的更多相关文章
- winform中生成TreeView树
无论是webform还是winform,TreeView都是常用功能.使用递归方法很方便. 下面分享一个小实例. 数据库中3个字段,分别是:ID,itemType_name,itemType_PID ...
- winform中的TreeView的数据绑定
#region 绑定TreeView /// <summary> /// 绑定TreeView(利用TreeNode) /// </summary> /// <param ...
- C# 中的treeview绑定数据库(递归算法)
近日面试的给我两道题目,一道是IQ测试,第二个就是题目所言 总共两个表 department(id int not null primary key,parentid int,name char(50 ...
- WinForm开发中针对TreeView控件改变当前选择节点的字体与颜色
本文转载:http://www.cnblogs.com/umplatform/archive/2012/08/29/2660240.html 在B/S开发中,对TreeView控件要改变当前选中节点的 ...
- WinForm控件TreeView 只部分节点显示 CheckBox
WinForm控件TreeView 只部分节点显示 CheckBox 用过asp.net的应该知道,要在treeview中实现上述功能可以使用ShowCheckBox 属性指定那些节点显示check ...
- WinForm中从SQLite数据库获取数据显示到DataGridView
1.关于Sqlite Sqlite是一款开源的.适合在客户端和嵌入式设备中使用的轻量级数据库,支持标准的SQL. 不像SqlServer或Oracle的引擎是一个独立的进程.通过TCP或命名管道等与程 ...
- Winform中Treeview控件失去焦点,将选择的节点设置为高亮显示 (2012-07-16 13:47:07)转载▼
Winform中Treeview控件失去焦点,将选择的节点设置为高亮显示 (2012-07-16 13:47:07)转载▼标签: winform treeview drawnode Treeview控 ...
- DropDownList怎样动态绑定数据库中的某一条数据
用Ajax动态绑定数据库的数据:点击后台查看代码,编写代码如下 if (!IsPostBack) { using (SnailTechDataContext con = new SnailTechDa ...
- winform中DataGridView实现分页功能
WinForm轻松实现自定义分页 (转载) WinForm轻松实现自定义分页 (转载) 转载至http://xuzhihong1987.blog.163.com/blog/static/26731 ...
随机推荐
- [转]git命令之git remote的用法
git remote git remote -v git init git add xxx git commit -m 'xxx' git remote add origin ssh://softw ...
- JavaFX 学习笔记——jfoenix类库学习——raised风格按钮创建
创建按钮 JFXButton jfxb = new JFXButton("hello"); jfxb.getStyleClass().add("button-raised ...
- 使用Firebug或chrome-devToolBar深入学习javascript语言核心
使用Firebug和chrome-devToolBar调试页面样式或脚本是前端开发每天必做之事.这个开发神器到底能给我们带来哪些更神奇的帮助呢?这几天看的一些资料中给了我启发,能不通过Firebug和 ...
- Python20-Day02
1.数据 数据为什么要分不同的类型 数据是用来表示状态的,不同的状态就应该用不同类型的数据表示: 数据类型 数字(整形,长整形,浮点型,复数),字符串,列表,元组,字典,集合 2.字符串 1.按索引取 ...
- 2018软工实践—Alpha冲刺(3)
队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作 协助后端界面的开发 搭建项目运行的服务器环境 ...
- 【树上DFS】Tree and Polynomials
http://codeforces.com/gym/101372 D push1[i][k]:所有操作1总共要让节点i下推多少系数k push2[i][k]:所有操作2总共要让节点i上推多少系数k s ...
- 福大软工1816 ·软工之404NoteFound团队选题报告
目录 NABCD分析引用 N(Need,需求): A(Approach,做法): B(Benefit,好处): C(Competitors,竞争): D(Delivery,交付): 初期 中期 个人贡 ...
- css3浏览器私有属性前缀使用详解
什么是浏览器私有属性前缀 CSS3的浏览器私有属性前缀是一个浏览器生产商经常使用的一种方式.它暗示该CSS属性或规则尚未成为W3C标准的一部分. 以下是几种常用前缀 -webkit- -moz- -m ...
- Spring源码解析 – AnnotationConfigApplicationContext容器创建过程
Spring在BeanFactory基础上提供了一些列具体容器的实现,其中AnnotationConfigApplicationContext是一个用来管理注解bean的容器,从AnnotationC ...
- 第五周PSP &进度条
团队项目PSP 一:表格 C类型 C内容 S开始时间 E结束时间 I时间间隔 T净时间(mins) 预计花费时间(mins) 讨论 讨论用户界面 9:27 10:42 18 57 60 分析与 ...