VB6 Treeview Image Loop 改变图像
VB6 Treeview Image Loop changing image
给定以下图像:
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
您的第一个 For Each
循环应该使用 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
给定以下图像:
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
您的第一个 For Each
循环应该使用 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