C#树菜单的问题
请教一下C#树菜单的问题。比如有两个表,表一[book] 里有 id,bookname,ParentID字段。 表二[authors]有 bookid,author,price,sex字段。表一的id 与表二的tbookid 关联。表一是树的表,我想点击一个树节点,就可以关联到authors表,并且把表二的数据显示在txtbox里。这样。谢谢
怎修改下面代码呢
namespace userTV
{
public partial class Form1 : Form
{
public DataSet ds = new DataSet();
public DataSet du = new DataSet();
public Form1()
{
InitializeComponent();
}
private void InitTreeView(TreeView treeView)
{
treeView.CheckBoxes = false;//不显示复选框
treeView.FullRowSelect = true;
ImageList imageList = new ImageList();
imageList.Images.Add(new Icon("Folder.ico"));
imageList.Images.Add(new Icon("OpenFolder.ico"));
imageList.Images.Add(new Icon("Book.ico"));
treeView.ImageList = imageList;//设置图像集合
treeView.LabelEdit = false;//设置不能编辑
treeView.PathSeparator = "\\";//用\符号为分隔符
treeView.Scrollable = true;//显示滚动条
treeView.ShowLines = true;//显示连线
treeView.ShowNodeToolTips = true;
treeView.ShowPlusMinus = true;//显示+-号
treeView.ShowRootLines = true;
// treeView.ImageList.Add(new Icon("Book.ico"));
treeView.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
}
public void AddTree(int ParentID, TreeNode pNode)
{
DataView dvTree = new DataView(ds.Tables[0]);
//过滤ParentID,得到当前的所有子节点
dvTree.RowFilter = "[PARENTID] = " + ParentID;
treeView1.ImageIndex = 0;
treeView1.SelectedImageIndex = 1;
foreach (DataRowView Row in dvTree)
{
TreeNode Node = new TreeNode();
Node.ImageIndex = 0;
Node.SelectedImageIndex = 1;
if (pNode == null)
{ //添加根节点
Node.Tag = Row["ID"].ToString();
Node.Text = Row["bookname"].ToString();
treeView1.Nodes.Add(Node);
AddTree(Int32.Parse(Row["ID"].ToString()), Node); //再次递归
}
else
{ //添加当前节点的子节点
Node.Tag = Row["ID"].ToString();
Node.Text = Row["bookname"].ToString();
pNode.Nodes.Add(Node);
treeView1.SelectedNode = Node;
AddTree(Int32.Parse(Row["ID"].ToString()), Node); //再次递归
}
}
}
private void AddChildNode(string strTag, string strNodeText)
{
//首先判断是否选定组件中的位置