/// <summary>
/// 动态的生成树,然后再选择要的某个节点
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBox1_MouseDown(object sender, MouseEventArgs e)
{
this.treeView1.Visible = true;
bindingtree();
this.textBox1.Text = this.treeView1.SelectedNode.Text.ToString();
} /// <summary>
/// 绑定树
/// </summary>
private void bindingtree()
{
this.tb_departmentTableAdapter.Fill(this.employeesDataSet.tb_department);
tblsetorginfo = this.employeesDataSet.tb_department.Copy();
DataTable tempdatatable = tblsetorginfo.Copy();
DataView viewsetorginfo = new DataView(tempdatatable);
viewsetorginfo.RowFilter = "Dept_level=0";
if (viewsetorginfo.Count > 0)param name
{
foreach (DataRowView myrow in viewsetorginfo)
{
string strenterprisename = myrow["Dept_Name"].ToString().Trim();
this.treeView1.Nodes.Add(new TreeNode(strenterprisename));
populatetreeview(treeView1.Nodes[0], myrow);
treeView1.SelectedNode = treeView1.Nodes[0];
this.treeView1.Show();
}
}
}
/// <summary>
/// 显示某单位的编码信息
/// </summary>
/// <param name="mynode"></param>
//private void inputtextbox2andtextbox3andtextbox4(TreeNode mynode)
//{
// tblsetorginfo = ployeesDataSet.tb_department;
// DataView dv = new DataView(tblsetorginfo);
// //DataRowView drv = new DataRowView(dv);
// dv.RowFilter = "Dept_Name='" + mynode.Text.ToString().Trim() + "'";
// foreach (DataRowView drv in dv)
// {
// Box2.Text = drv["Dept_level"].ToString().Trim();
// Box3.Text = drv["Selfdept_ID"].ToString().Trim();
// Box4.Text = drv["Dept_ID"].ToString().Trim();
// }
// strtextbox1text = textBox4.Text.ToString().Trim();
//}
/// <summary>
/// 递归的方法实现树的生成
/// </summary>
/// <param name="parentpart"></param>
/// <param name="parentnode"></param>
/// <param name="parentrow"></param>
private void populatetreeview(TreeNode parentnode, DataRowView parentrow)
{
string strenterprisename = "";
DataTable tempdatatable = this.employeesDataSet.tb_department.Copy();
DataView viewsetorginfo = new DataView(tempdatatable);
viewsetorginfo.RowFilter = "Parent_ID='" + parentrow["Selfdept_ID"].ToString().Trim() + "'";
foreach (DataRowView myrow in viewsetorginfo)
{
strenterprisename = myrow["Dept_Name"].ToString().Trim();
TreeNode mynode = new TreeNode(strenterprisename);
parentnode.Nodes.Add(mynode);
populatetreeview(mynode, myrow);
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论