有一个treeviewGroup
   G1
      aaa
      bbb
   G2
      ccc
      ddd
   G3 
      eee
每个节点都有checkbox,能不能遍历这棵树,记录下所有选中节点的内容呢?
谢谢。

解决方案 »

  1.   

    javascript:var trnSelected;
    trnSelected = treeview1.getTreeNode(treeview1.selectedNodeIndex);
    var text=trnSelected.getAttribute("text")vb.net:
    Dim trnSelected As TreeNode
    trnSelected = treeview1.GetNodeFromIndex(treeview1.SelectedNodeIndex)
    dim text=trnSelected.Text
      

  2.   

    to: justdoit006(我的心太乱
    我这样:
     Dim trnSelected As New Microsoft.Web.UI.WebControls.TreeNode()
            trnSelected = tvwGroup.GetNodeFromIndex(tvwGroup.SelectedNodeIndex)
            If trnSelected.Checked = True Then
                 Me.TextBox1.Text = trnSelected.Text
            End If
    如果选中根结点,则显示“Group”
    如果没选中根结点,选中其他子结点的话,则什么也不显示。怎样才能遍历到子结点呢?例如选中,aaa,则显示”aaa“?
      

  3.   

    Dim trnSelected As TreeNode
    Dim intNodeCounts As IntegertrnSelected = tvwGroup.GetNodeFromIndex(tvwGroup.SelectedNodeIndex)'得到选择的节点
    intNodeCounts = trnSelected.Nodes.Count
    If intNodeCounts = 0 Then'选择了子节点
       .......
    Else'选择了父节点
     Me.TextBox1.Text = trnSelected.Text
     end if
      

  4.   

    Else'选择了父节点 Dim trnNode As TreeNode
     For i = 0 To intNodeCounts - 1
         trnNode = trnSelected.Nodes(i)
         此处可以继续判断...
     next
    end if
      

  5.   

    用递归做
       Private Sub Cpoint(ByVal CNode As Microsoft.Web.UI.WebControls.TreeNode)
            Dim cp As Short
            Dim j As Short
            cp = CNode.Nodes.Count
            If cp = 0 and CNode.Text="aaa" Then
               response.write(CNode.Text)
            Else
                For j = 0 To cp - 1
                    Call Cpoint(CNode.Nodes(j))
                Next
            End If
        End Sub