我的代码,想做一个循环,作不料
Private Sub trvProdOne_NodeCheck(ByVal Node As MSComctlLib.Node)
Dim i As Integer
    If Node.Checked = True Then
        For i = 0 To Node.Children
            Node.Child.Checked = True '只能一个一个往下走啊
            Node.Child.Next.Checked = True
            Node.Child.LastSibling.Checked = True
        Next
    Else
        '.........
    End If
End Sub

解决方案 »

  1.   

    '*****对所选择的节点进行打勾操作******
    Private Sub TrvMK_NodeCheck(ByVal Node As MSComctlLib.Node)
        If Not Node.Parent Is Nothing Then
           If Node.Parent.Checked = False Then
              Node.Parent.Checked = Node.Checked
           End If
        End If
        CheckNode Node
    End Sub
      

  2.   

    Private Sub CheckNode(ByRef Node As Node)
    Dim obj    As Node
    Dim I      As Integer
        Set obj = Node.Child
        For I = 1 To Node.Children
            obj.Checked = Node.Checked
            CheckNode obj
            Set obj = obj.Next
        Next I
    End Sub
      

  3.   

    '----------------------------------------------------------------------------
    '
    'Author:lihonggen0
    'Date:2003-1-20
    '功能:选择Treeview节点下所有节点
    '----------------------------------------------------------------------------Private Sub Form_Load()
        TreeView1.Checkboxes = True
        TreeView1.Nodes.Add , "R", "root", "root"
        TreeView1.Nodes.Add "root", tvwChild, "key1", "aa"
        TreeView1.Nodes.Add "key1", tvwChild, "key11", "ccc"    TreeView1.Nodes.Add "root", tvwChild, "key2", "bb"
        TreeView1.Nodes.Add "key2", tvwChild, "key21", "ddd"
        TreeView1.Nodes.Add "key2", tvwChild, "key211", "eee"
        For I = 1 To TreeView1.Nodes.Count
            TreeView1.Nodes(I).Expanded = True
        Next
    End Sub
     
    Private Sub CheckChild(ByVal Node As MSComctlLib.Node, ByVal bCheck As Boolean, Optional ByVal bNext As Boolean = True, Optional ByVal bChild As Boolean = True)
         If Not Node Is Nothing Then
            Node.Checked = bCheck
            If Node.Children And bChild Then
                    Call CheckChild(Node.Child, bCheck, True, True)        '对子节点
            End If
            If bNext Then
                Call CheckChild(Node.Next, bCheck, True, bChild)          '对同一层节点
            End If
         End If
    End SubPrivate Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
        Call CheckChild(Node, Node.Checked, False, True)                    '处理子节点
    End Sub
      

  4.   

    http://community.csdn.net/Expert/topic/3097/3097452.xml?temp=1.618594E-02
      

  5.   

    用函数递归调用不就可以了哦。用For Each枚举节点
      

  6.   

    告诉你一个中国最大开发文档搜索引擎,还有大量源代码下载。
    去看看可能会有帮助。
    http://www.csdn.com.cn
      

  7.   

    用递归。下面是我写的代码:选中父项时则自动选中其所有子项;当其中一个子项取消选择时,父项也自动被取消选择;当所有同级子项都被选中后,其父项也被自动选中Private Sub SelectedNode(ByVal pNode As Node)
      If TrView.Checkboxes = False Then Exit Sub  Dim i         As Integer
      Dim bAll      As Boolean  If pNode.Checked = True Then
        If pNode.Children > 0 Then
          pNode.Child.FirstSibling.Checked = True
          Call SelectedNode(pNode.Child.FirstSibling)
          For i = 3 To pNode.Children
            pNode.Child.Next.Checked = True
            Call SelectedNode(pNode.Child.Next)
          Next i
          pNode.Child.LastSibling.Checked = True
          Call SelectedNode(pNode.Child.LastSibling)
        End If  Else
        '    If Not pNode.Parent Is Nothing Then
        '      Call SelectedFatherNode(pNode)
        If pNode.Children > 0 Then
          pNode.Child.FirstSibling.Checked = False
          Call SelectedNode(pNode.Child.FirstSibling)
          For i = 3 To pNode.Children
            pNode.Child.Next.Checked = False
            Call SelectedNode(pNode.Child.Next)
          Next i
          pNode.Child.LastSibling.Checked = False
          Call SelectedNode(pNode.Child.LastSibling)
        End If
        '    End If
      End If
      '修改时更改状态
      Call SelectedFatherNode(pNode)
    End SubPrivate Sub SelectedFatherNode(ByVal pNode As Node)
      If TrView.Checkboxes = False Then Exit Sub  Dim i         As Integer
      Dim bAll      As Boolean  If pNode.Checked = True Then
        '修改时更改状态
        If Not pNode.Parent Is Nothing Then
          Set pNode = pNode.Parent
          bAll = True
          bAll = bAll And pNode.Child.FirstSibling.Checked
          For i = 3 To pNode.Children
              bAll = bAll And pNode.Child.Next.Checked
          Next i
          bAll = bAll And pNode.Child.LastSibling.Checked
          If bAll = True Then pNode.Checked = True
          Call SelectedFatherNode(pNode)
        End If
      Else
        If Not pNode.Parent Is Nothing Then
          pNode.Parent.Checked = False
          Call SelectedFatherNode(pNode.Parent)
        End If
      End IfEnd Sub
      

  8.   

    如何选中父结点,所有子结点的TEXT赋给一个数组?
      

  9.   

    Private Sub trvProdOne_NodeCheck(ByVal Node As MSComctlLib.Node)
    Dim i As Integer
    Dim n As Object
    Set n = Node.Child
    For i = 1 To Node.Children
        n.Checked = Node.Checked
        Set n = n.Next
    Next i
    End Sub