不是有个TreeView控件吗?你直接用不就可以啦?
要代码控制的,
海鸽 is My Lover!!
//处理TreeView中的事件
private void TreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection("Data Source=localhost;Initial Catalog=student;Integrated Security=True");
switch (TreeView.SelectedNode.Name)
{
case "girl":
SqlDataAdapter daAuthors = new SqlDataAdapter("Select ID ,sno,sname,sex From student where sex=0", conn);
conn.Open();
daAuthors.Fill(ds, "student");
// conn.Close() '在填充完ds后关闭连接,接着对ds进行操作
dataGrid1.DataSource = ds.Tables[0];//vb.net上使用这样的语句:ds.Tables("student");
conn.Close();
break;
case "boy":
SqlDataAdapter daAuthor = new SqlDataAdapter("Select ID ,sno,sname,sex From student where sex=1", conn);
conn.Open();
daAuthor.Fill(ds, "student");
// conn.Close() '在填充完ds后关闭连接,接着对ds进行操作
dataGrid1.DataSource = ds.Tables[0];//vb.net上使用这样的语句:ds.Tables("student");
conn.Close();
break;
}
}
//"girl"和"boy" 是 TreeView的两个分支,点击一下就能在DataGrid里面显示对应的数据
[此贴子已经被作者于2007-4-3 11:15:36编辑过]