部门树形结构,使用Treeview控件显示部门
部门树形结构。设计张部门表用于存储部门编码、名称、上级部门id,使用Treeview控件显示部门树,并实现部门增删改、移动、折叠等功能。特别提示,部门有层级关系,可用donetbar的adtree控件

代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
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 Form1_Load(object sender, EventArgs e)
{
BindTree("");
}
DBHelp s = new DBHelp();
private void BindTree(string pid)
{
string str = "select * from biao where SJ_id=" + int.Parse(pid);
DataTable ta = s.getTableBySql(str);
if (ta.Rows.Count > )
{
for (int i = ; i < ta.Rows.Count; i++)
{
TreeNode node = new TreeNode();
node.Text = ta.Rows[i]["name"].ToString();
node.Tag = ta.Rows[i]["id"].ToString();
this.treeView1.Nodes.Add(node);
BindNode(node);
}
}
}
private void BindNode(TreeNode nd)
{
string str = "select * from biao where SJ_id="+ Convert.ToString(nd.Tag);
DataTable ta = s.getTableBySql(str);
for (int i = ; i < ta.Rows.Count; i++)
{
TreeNode node = new TreeNode();
node.Text = ta.Rows[i]["name"].ToString();
node.Tag = ta.Rows[i]["id"].ToString();
nd.Nodes.Add(node);//重点
BindNode(node);
}
} private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
if (treeView1.SelectedNode != null)//重点部分
{
txt_id.Text= treeView1.SelectedNode.Tag.ToString();//取值
txt_name.Text= treeView1.SelectedNode.Text; string str = "select * from biao where id=" + int.Parse(txt_id.Text);
DataTable ta = s.getTableBySql(str);
txt_sj.Text = ta.Rows[]["SJ_id"].ToString();
}
}
//添加
private void buttonX1_Click(object sender, EventArgs e)
{
string sql_add =string.Format("insert into biao(name,SJ_id) values('{0}',{1})", txt_name.Text,int.Parse(txt_sj.Text));
if (s.ExecuteIDUBySql(sql_add) > )
{
MessageBox.Show("添加成功!", "消息");
}
else
{
MessageBox.Show("添加失败!", "消息");
}
treeView1.Nodes.Clear();
BindTree("");
}
}
}
部门树形结构,使用Treeview控件显示部门的更多相关文章
- 如何:使用TreeView控件实现树结构显示及快速查询
本文主要讲述如何通过使用TreeView控件来实现树结构的显示,以及树节点的快速查找功能.并针对通用树结构的数据结构存储进行一定的分析和设计.通过文本能够了解如何存储层次结构的数据库设计,如何快速使用 ...
- asp.net TreeView控件绑定数据库显示信息
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- [转] C#2010 在TreeView控件下显示路径下所有文件和文件夹
原文 张丹-小桥流水,C#2010 在TreeView控件下显示路径下所有文件和文件夹 C#2010学习过程中有所收获,便总结下来,希望能给和我一样在学习遇到困难的同学提供参考. 本文主要介绍两个自定 ...
- Win32中TreeView控件的使用方法,类似于资源管理器中文件树形显示方式
首先是头文件,内容如下: #include <tchar.h> #include "..\CommonFiles\CmnHdr.h" #include <Wind ...
- 在TreeView控件节点中显示图片
实现效果: 知识运用: TreeView控件中Nodes集合的Add方法 //创建节点并将节点放入集合中 public virtual TreeNode Add (string key,string ...
- TreeView控件概述、属性与方法
1.作用:用于显示Node结点的分层列表.2.添加到控件箱菜单命令:工程 | 部件,在部件对话框中选择:Microsoft Windows Common Controls 6.03.TreeView控 ...
- WPF中TreeView控件数据绑定和后台动态添加数据(一)
数据绑定: 更新内容:补充在MVVM模式上的TreeView控件数据绑定的代码. xaml代码: <TreeView Name="syntaxTree" ItemsSourc ...
- asp TreeView控件的使用
相对于之前发过一个TreeView控件的使用方法 本次利用js操作,页面无刷新,性能提高 Css编码可能时我的模板页样式被继承下来,导致页面变乱,不需要的可以去掉 前台 <style> . ...
- Winform TreeView控件技巧
在开发的时候经常使用treeview控件来显示组织结构啊,目录结构啊,通常会结合属性checkedboxs,来做选中,取消的操作下面是一个选中,取消的小例子,选中节点的时候,如果节点存在子节点,可以选 ...
随机推荐
- CodeForces 219B Special Offer! Super Price 999 Bourles!
Special Offer! Super Price 999 Bourles! Time Limit:1000MS Memory Limit:262144KB 64bit IO For ...
- herf窗口点击跳转
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ubuntu下解压zip文件乱码
安装unar 即可解决问题 sudo apt get install unar
- CUBRID学习笔记 28 执行sql脚本文件
一下命令在csql下执行. insert_commands.sql为sql脚本文件 ;CL ;READ insert_commands.sql ;RU 第一行的cl 清空命令缓存,等同clear第二行 ...
- 二叉树hdu1710
学习二叉树,看了两天也不明白,唉!acm之路让我体验到要付出巨大的努力,废话不多说,看我网上找到的代码: 此题题意很明确,给你先序遍历,中序遍历,求后序遍历.但代码就让我找不到东西了. http:// ...
- Codeforces Round #279 (Div. 2) C. Hacking Cypher 前缀+后缀
C. Hacking Cypher time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- GATK3.2.2小结(转载)
http://blog.csdn.net/skenoy/article/details/38346489 经过几天的摸索和网上资料的查询对GATK软件有点小心得,现总结如下: 1. fasta文件最好 ...
- [转载]bigtable 中文版
转载厦门大学林子雨老师的译文 原文: http://dblab.xmu.edu.cn/post/google-bigtable/ Google Bigtable (中文版) 林子雨2012-05-08 ...
- java实现将资源文件转化成sql语句导入数据库
文档结构
- hdu4720Naive and Silly Muggles
链接 一直理解的最小覆盖圆就是外接圆..原来还要分钝角和锐角... 钝角的话就为最长边的中点,对于这题分别枚举一下外接圆以及中点的圆,判一下是不是在园外. #include <iostream& ...