treeview绑定怎么用TreeView绑定数据库里的省市县数据

treeview绑定  时间:2021-06-04  阅读:()

C#中TreeView与数据库绑定?

递归方法。

// /// TreeView数据绑定 /// /// protected void CreateTreeView() { TreeNode rootNode = new TreeNode(); rootNode.Text = "全部"; rootNode.Value = "-1"; BasicTypeTreeView.Nodes.Add(rootNode); BasicInformationManager BasicManager = new BasicInformationManager(); var tlist = BasicManager.GetAllBasicInfoTypes(); foreach (Model.BasicInforType mtype in tlist) { if (mtype.ParentID == 0) { TreeNode Node = new TreeNode(); //添加根节点 Node.Text = mtype.BasicTypeName; Node.Value = mtype.ID.ToString(); Node.ToolTip = "编码" + mtype.BasicCode; getSubNode(ref Node, mtype.ID); rootNode.ChildNodes.Add(Node); } } } /// /// 获取treeView子节点 /// /// /// public void getSubNode(ref TreeNode node, int item) { BasicInformationManager BasicManager = new BasicInformationManager(); var tlist = BasicManager.GetBasicInforTypeByParentId(item); if (tlist.Count > 0) { foreach (Model.BasicInforType m in tlist) { TreeNode subNode = new TreeNode(); subNode.Text = m.BasicTypeName; subNode.Value = m.ID.ToString(); subNode.ToolTip = "编码" + m.BasicCode; getSubNode(ref subNode, m.ID); node.ChildNodes.Add(subNode); //进行子节点循环添加 } } }

C#手动绑定treeview怎么写来着?

private void addTree(TreeNode tn, string dept) { DataTable dt = cf.getDataTable("select 部门名称 from 部门表 where 上级部门= + dept + "); foreach (DataRow dr in dt.Rows) { TreeNode ctn = new TreeNode(dr[0].ToString()); ctn.SelectedImageIndex = 0; ctn.ImageIndex = 0; DataTable dtg = cf.getDataTable("select 岗位名称 from 岗位表 where 所属部门= + dr[0].ToString() + "); foreach (DataRow drg in dtg.Rows) { TreeNode tng = new TreeNode(drg[0].ToString()); tng.SelectedImageIndex = 1; tng.ImageIndex = 1; ctn.Nodes.Add(tng); } tn.Nodes.Add(ctn); addTree(ctn,dr[0].ToString()); } }

private void FormManagerCenter_Load(object sender, EventArgs e) { TreeNode tn = new TreeNode("公司架构"); addTree(tn, "公司架构"); treeView1.Nodes.Add(tn); }

利用递归原理

WinForm中数据绑定TreeView

这是一个绑定的方法,可以参考一下! public void InitTvArea() { Area.Nodes.Clear(); TreeNode rootNode =Area.Nodes.Add("区域划分"); IList<Area> listArea = AreaManager.Get_Area_Father(); foreach (Area area in listArea) { TreeNode node = new TreeNode(area.AreaName); //根节点 Area areaid = AreaManager.Get_Area_idByName(area.AreaName); IList<Area> listAreaChild = AreaManager.Get_Area_Childs(areaid.Id + "___"); if (listAreaChild.Count != 0) { foreach (Area areaChild in listAreaChild) { TreeNode childNode = new TreeNode(areaChild.AreaName); //子节点 node.Nodes.Add(childNode); } } rootNode.Nodes.Add(node); //添加字节点 } rootNode.Expand(); }

怎么用TreeView绑定数据库里的省市县数据

数据表: CREATE TABLE CateTable ( [ID] [int] IDENTITY (1, 1) NOT NULL , [CateName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL , [RootID] [int] NOT NULL , [ParentID] [int] NOT NULL ) GO 存储过程: CREATE PROCEDURE CateTable_GetList AS BEGIN Select CateID, CateName, RootID, ParentID From CateTable Order By CateID,RootID,ParentID END 代码: private void MainForm_Load(object sender, EventArgs e) { //从数据库中读取数据 SqlConnection con = new SqlConnection(ConnString.ConStr); SqlCommand cmd = new SqlCommand("CateTable_GetList", con); cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); try { sda.Fill(ds); } catch { } finally { cmd = null; con.Close(); } //往TreeView中添加树节点 //添加根节点 TreeNode tn = new TreeNode(); tn.Text = "种类"; tn.Name = "0";//Name作为ID tn.Tag = "0";//Tag作为RootID tn.ImageIndex = 0; tn.SelectedImageIndex = 0; tv.Nodes.Add(tn);//该TreeView命名 tv.SelectedNode =.TopNode; //把其他节点加上去 if (ds != null) { foreach (DataRow dr in ds.Tables[0].Rows) { tn = new TreeNode(); tn.Text = dr["CateName"].ToString(); tn.Name = dr["CateID"].ToString();//Name作为CateID tn.Tag = dr["RootID"].ToString();//Tag作为RootID tn.ImageIndex = 1; tn.SelectedImageIndex = 1; //判断是否为主节点 if (dr["CateID"].ToString() == dr["RootID"].ToString()) { //主节点 tv.SelectedNode =.TopNode; } else { //其他节点 if .SelectedNode.Name != dr["ParentID"].ToString()) { TreeNode[] tn_temp =.Nodes.Find(dr["ParentID"].ToString(), true); if (tn_temp.Length > 0) { tv.SelectedNode = tn_temp[0]; } } } tv.SelectedNode.Nodes.Add(tn); } tv.ExpandAll();//展开TreeView tv.SelectedNode =.TopNode; } }

如何低价香港服务器购买?有没有便宜的香港服务器推荐?

如何低价香港服务器购买?想要做一个个人博客,想用香港服务器,避免繁琐备案,性能不需要多高,只是记录一些日常而已,也没啥视频之类的东西,想问问各位大佬有没有低价的香港服务器推荐?香港距大陆近,相比美国服务器最大的优势在于延迟低,ping值低,但是带宽紧张,普遍都是1M,一般戏称其为“毛细血管”。同时价格普遍高,优质稳定的一般价格不菲。大厂云梯队阿里云、腾讯云两家都有香港服务器,要注意的是尽量不要选择...

Digital-vm80美元,1-10Gbps带宽日本/新加坡独立服务器

Digital-vm是一家成立于2019年的国外主机商,商家提供VPS和独立服务器租用业务,其中VPS基于KVM架构,提供1-10Gbps带宽,数据中心可选包括美国洛杉矶、日本、新加坡、挪威、西班牙、丹麦、荷兰、英国等8个地区机房;除了VPS主机外,商家还提供日本、新加坡独立服务器,同样可选1-10Gbps带宽,最低每月仅80美元起。下面列出两款独立服务器配置信息。配置一 $80/月CPU:E3-...

Tudcloud(月付7.2美元),香港VPS,可选大带宽或不限流量

Tudcloud是一家新开的主机商,提供VPS和独立服务器租用,数据中心在中国香港(VPS和独立服务器)和美国洛杉矶(独立服务器),商家VPS基于KVM架构,开设在香港机房,可以选择限制流量大带宽或者限制带宽不限流量套餐。目前提供8折优惠码,优惠后最低每月7.2美元起。虽然主机商网站为英文界面,但是支付方式仅支付宝和Stripe,可能是国人商家。下面列出部分VPS主机套餐配置信息。CPU:1cor...

treeview绑定为你推荐
声纹识别想了解声纹技术的真实环境准确率如何,君林科技的声纹识别技术怎么样企业资源管理系统企业内部管理系统有哪些腾讯汽车网可以了解汽车知识的权威网站大概有哪些12种颜色水粉颜料调色过程十二种颜色网络电话永久免费打有没有永久免费的网络电话jstz请帮忙翻译jstz江苏泰州市地税如何申报?熊猫烧香病毒下载熊猫烧香病毒?assemblyinfoLOL的 X、L、CS 是什么意思币众筹收益权众筹为什么有吸引力
北京域名注册 俄罗斯vps 汉邦高科域名申请 云网数据 winscp 国外服务器 patcha dropbox网盘 南昌服务器托管 合租空间 789电视网 双11秒杀 免费dns解析 西安服务器托管 华为k3 后门 攻击服务器 葫芦机 privatetracker phpinfo 更多