详细代码如下:
private void initTree()
{
///初始化可选择的人员
this.treeView1.Nodes.Clear();
TreeNode RootNode=null,ZMCNode=null,RYNode=null;
RootNode = new TreeNode();
RootNode.Tag = "-1";
RootNode.Text = "所有经办人员";
公共类.Model.人员基本信息 ry=new 公共类.Model.人员基本信息();
System.Data.DataTable table = ry.GetTable("RYLB=1");
if (table != null)
{
string[] ZB = new string[1];
ZB[0] = "RYZB";
System.Data.DataTable newTable = table.DefaultView.ToTable(true, ZB);
foreach (DataRow ZRow in newTable.Rows)
{
ZMCNode = new TreeNode();
ZMCNode.Text = ZRow["RYZB"].ToString(); ;
ZMCNode.Tag = "-2";
System.Data.DataRow[] RYRow = table.Select("RYZB='" + ZRow["RYZB"].ToString() + "'", "");
foreach (DataRow Row in RYRow)
{
RYNode = new TreeNode();
RYNode.Text = Row["RYXM"].ToString();
RYNode.Tag = Row["RYBH"].ToString();
ZMCNode.Nodes.Add(RYNood);
}
RootNode.Nodes.Add(ZMCNood);
}
}
this.treeView1.Nodes.Add(RootNood);
}
效果如下: