求:C#动态邦定TreeView的代码
求:C#动态邦定TreeView的代码 --------------------编程问答-------------------- private void ShowForm(){
treeView1.Nodes.Clear();
System.Windows.Forms.TreeNode mNode = new TreeNode("全部");
//mNode.ImageIndex =1;
treeView1.Nodes.Add(mNode);
//假设DataSet 已经取得
System.Windows.Forms.TreeNode nNode = new TreeNode("在职");
treeView1.Nodes.Add(nNode);
System.Windows.Forms.TreeNode pNode = new TreeNode("离职");
treeView1 = new System.Windows.Forms.TreeView();
treeView1.TopNode.Nodes.Add(nNode);
treeView1.TopNode.Nodes.Add(pNode);
treeView1.Select();
SqlConnection con= new SqlConnection("Server=.;database=JCOA_Data;uid=sa;pwd=sasa");
string sql = "select iPersonId,vcName,vcNickname from JCOA_Con_OrgPersons";
SqlDataAdapter com = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
com.Fill(ds, "0");
if (ds.Tables[0].Rows.Count <= 0)
{
return;
}
else
{
// add Add some childtreenodes
foreach (DataRow dr in ds.Tables[0].Rows)
{
System.Windows.Forms.TreeNode aNode = new TreeNode(dr["vcName"].ToString());
System.Windows.Forms.TreeNode bNode = new TreeNode(dr["vcName"].ToString());
treeView1.Nodes[0].Nodes[0].Nodes.Add(aNode);
treeView1.Nodes[0].Nodes[1].Nodes.Add(bNode);
}
}
}
补充:.NET技术 , C#