求一个winform中treeview实例,其中左边是treeview右边是listview,双击左边节点,能在右边显示出相关详细信息来(源代码)
如题:
请各位大侠帮帮忙。我是C#初学者,时间紧迫,唯有求大虾帮忙了!
------解决方案--------------------
调用treeview的select事件啊!给你个我写过的例子 你参考下吧:
private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
tree1 = treeView1.SelectedNode.Text;
treeView2.Nodes.Clear();
string cconnect_string = @"Data Source="+ip+",1433;Network Library = DBMSSOCN;Initial Catalog=HY_PoliceVedioDB;user id=sa;pwd=1;Persist Security Info = true";
SqlConnection conn = new SqlConnection(cconnect_string);
conn.Open();
if (conn.State == ConnectionState.Open)
{
label1.Text = "open";
}
else
{
label1.Text = "失败";
}
string value = treeView1.SelectedNode.Text.ToString();
string sql = "select ID from PoliceOrg where PoliceOrg.Name ='" + value + "'";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds, "权限");
conn.Close();
//MessageBox.Show(ds.Tables[0].Rows.Count.ToString());
if (ds.Tables[0].Rows.Count >= 1)
{
string value1 = ds.Tables[0].Rows[0][0].ToString();
//MessageBox.Show(value1);
conn.Open();
string sql1 = "select Number,Name from PoliceMan where OrgID =" + value1 + "";
SqlDataAdapter da1 = new SqlDataAdapter(sql1, conn);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "用户1");
conn.Close();
if (ds1.Tables[0].Rows.Count >= 1)
{
// MessageBox.Show(ds1.Tables[0].Rows[0][0].ToString());
for (int k = 0; k < ds1.Tables[0].Rows.Count; k++)
{
TreeNode nd = new TreeNode();
nd.Text = "警员编号:" + ds1.Tables[0].Rows[k][0].ToString() +":"+ "警员名:" + ds1.Tables[0].Rows[k][1].ToString();
treeView2.Nodes.Add(nd);
}
}
}
}
我这个写的时两个treeview的控制 你可以相应的把treeview2修改为你需要的listview,再做相应修改就OK了