根节点为0 ,父节点有若干,父节点下又有叶节点,比如A为父节点,其下有叶节点1,2,3,(左边有checkbox) 我现在想在lable 中显示所选叶节点的值,请问如何遍历?已经动态邦定了treeview
if (!IsPostBack)
        {
            string L_sql1 = "select * from 部门表";
            DataView dv = drv(L_sql1);
            foreach (DataRowView dtt in dv)
            {
                TreeNode tn = new TreeNode();
                tn.Text = dtt["所在部门"].ToString();
                tn.Value = dtt["部门编号"].ToString();
                tn.Expanded = false;                TreeView1.Nodes.Add(tn);
                addchild(tn);
            }
        }

解决方案 »

  1.   

    protected void Button6_Click(object sender, EventArgs e)
        {
           
            if (TreeView1.CheckedNodes.Count > 0)
            {
                foreach (TreeNode tn in TreeView1.Nodes .)
                {
                    if (tn.ChildNodes.Count > 0)
                    {
                        foreach (TreeNode tn1 in tn.ChildNodes)
                        {
                            Label2 .Text +=  tn1.Text + ",";
                            
                        }
                    }            }
            }
             
          } 
    这个方法只能显示父节点下所有节点的内容,而我要显示选定叶节点的内容,不知如何?
      

  2.   


     private void tvwClass_AfterSelect(object sender, TreeViewEventArgs e)
    {
         MessageBox.Show(e.Node.Text);
    }
      

  3.   

    已经找到相关方法了http://community.csdn.net/Expert/TopicView3.asp?id=5005301
      

  4.   

    用 jsp写一个函数参考http://community.csdn.net/Expert/TopicView3.asp?id=5005301