C#手动绑定treeview怎么写来着?
- 提问者网友:富士山上尢
- 2021-04-21 10:09
- 五星知识达人网友:三千妖杀
- 2021-04-21 11:31
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);
}
利用递归原理
- 1楼网友:我住北渡口
- 2021-04-21 12:11
treeNode node=new treeNode("哈哈"); //创建项
node.nodes.add(new treeNode("嘿嘿")) ; //创建绑定子项
this.treeview.nodes.add(node); //绑定到控件
完毕 还有问题 请追问