TreeView 控件问题
SqlConnection conn = ClassLibraryMain.Bind_Connection.BuildNewConnection(); string str = "select PersonnelId,YourName from Personnel_Table;
treeView1.Nodes.Clear();
SqlDataAdapter da = new SqlDataAdapter(str, conn);
DataSet ds = new DataSet();
da.Fill(ds, "PersonnelTable");
TreeNode root = new TreeNode("所有人");
this.treeView1.Nodes.Add(root);
foreach (DataRow dr in ds.Tables["PersonnelTable"].Rows)
{
TreeNode newTree = new TreeNode();
newTree.Text = dr["YourName"].ToString();
root.Nodes.Add(newTree);
//TreeNode idTree = new TreeNode();
//idTree.Text = dr["PersonnelId"].ToString();
//root.Nodes.Add(idTree);
}
treeView1.Nodes[0].Expand();
我想在选择某个节点时,取得该 YourName 的对应的 PersonnelId