VB6树视图图像循环更改图像

VB6树视图图像循环更改图像,vb6,Vb6,给出以下图像: image=4是绿色图标 image=3是红色图标 我的ii索引没有移动到下一项,它在通过循环时显示的索引与我通过单步通过每个循环检查的索引相同 我想将所有子项图标更改为Image=3 Dim FoundIt As Boolean, ii As Integer, ix As Integer Dim NodX As Node, NodX2 As Node On Error Resume Next For Each NodX2 In TreeView2.Nodes If

给出以下图像:

image=4是绿色图标

image=3是红色图标

我的
ii
索引没有移动到下一项,它在通过循环时显示的索引与我通过单步通过每个循环检查的索引相同

我想将所有子项图标更改为Image=3

Dim FoundIt As Boolean, ii As Integer, ix As Integer
Dim NodX As Node, NodX2 As Node

On Error Resume Next

For Each NodX2 In TreeView2.Nodes

    If NodX2.Parent.Image = 4 Then
        ii = NodX2.Child.Index
        TreeView2.Nodes(ii).Parent.Child.Image = 3
        Debug.Print ii ' when i step through it repeats the same index,only the first child changes to image = 3
        Pause 0
    End If
Next

每个循环的第一个
应该使用
NodX
。在该循环中,您可以使用
NodX2
遍历
NodX
的所有子循环:

Dim objNode As Node
Dim objChildNode As Node
Dim iCounter As Integer
Dim fProceed As Boolean

On Error Resume Next

For Each objNode In TreeView2.Nodes

    If objNode.Image = 4 Then

        ' Check for Children
        If objNode.Children > 0 Then

            ' Get first Child
            Set objChildNode = objNode.Child

            ' Initialize flag
            fProceed = True

            ' Loop through all children
            For iCounter = 1 To objNode.Children

                ' Set image to 3 if it was 5
                If objChildNode.Image <> 5 Then
                    fProceed = False
                    Exit For
                End If

                ' Get next node
                Set objChildNode = objChildNode.Next

            Next

            If fProceed Then

                ' Get first Child again
                Set NodX2 = NodX.Child

                ' Loop through all children
                For iCounter = 1 To objNode.Children

                    ' Set image to 3
                    objChildNode.Image = 3

                    ' Get next node
                    Set objChildNode = objChildNode.Next

                Next

            End If

        End If

    End If

Next
Dim objNode作为节点
Dim objChildNode As节点
作为整数的Dim I计数器
Dim fProceed作为布尔值
出错时继续下一步
对于TreeView2.Nodes中的每个objNode
如果objNode.Image=4,则
“看看有没有孩子
如果objNode.Children>0,则
“生第一个孩子
设置objChildNode=objNode.Child
'初始化标志
fProceed=True
“循环遍历所有的孩子
对于iCounter=1到objNode.Children
'如果图像为5,则将其设置为3
如果是objChildNode.Image 5,则
fProceed=False
退出
如果结束
'获取下一个节点
设置objChildNode=objChildNode.Next
下一个
如果是这样的话
“再生第一个孩子
设置NodX2=NodX.Child
“循环遍历所有的孩子
对于iCounter=1到objNode.Children
'将图像设置为3
objChildNode.Image=3
'获取下一个节点
设置objChildNode=objChildNode.Next
下一个
如果结束
如果结束
如果结束
下一个

El tienne Laneville感谢您抽出时间回复,我想请问您是否可以发布一个更新代码,向我展示如何使用advanced进行感谢。我怀疑
NodX.Parent.Image=4
应该是
NodX.Image=4
。是否要将具有
图像
作为4的节点的所有子节点更改为具有
图像
作为3?代码按我的要求工作,但不是NodX.Parent.Image=4子节点的其他节点变为红色?,我只希望NodX.Parent.Image=4个孩子受到影响。如果NodX2.Parent.Image=4,那么NodX2.Image=3结束,如果我认为这样做有效