使用VB6将缺少的节点从Treeview1添加到Treeview2
我想扫描和匹配TreeView 2中TreeView的项目,并将子项目添加到TreeView 2中 以下是我当前的代码:使用VB6将缺少的节点从Treeview1添加到Treeview2,vb6,Vb6,我想扫描和匹配TreeView 2中TreeView的项目,并将子项目添加到TreeView 2中 以下是我当前的代码: Dim FoundIt As Boolean, ii As Integer, ix As Integer Dim NodX As Node, NodX2 As Node, namme As String On Error Resume Next For Each NodX In TreeView1.Nodes ii = NodX.Index For Each Nod
Dim FoundIt As Boolean, ii As Integer, ix As Integer
Dim NodX As Node, NodX2 As Node, namme As String
On Error Resume Next
For Each NodX In TreeView1.Nodes
ii = NodX.Index
For Each NodX2 In TreeView2.Nodes
ix = NodX.Index
On Error Resume Next
If NodX.FullPath = NodX2.FullPath Then
If TreeView1.Nodes(ii).Parent.Text = TreeView2.Nodes(ix).Parent.Text Then
If TreeView1.Nodes(ii).Parent.Image = 9 And TreeView1.Nodes(ii).Image = 3 Then
namme = TreeView2.Nodes(ix).Parent.Key
TreeView2.Nodes.Add namme, tvwChild, TreeView1.Nodes(ii).Parent.Child.Text, TreeView1.Nodes(ii).Parent.Child.Text, 5
Pause 0
End If
End If
End If
'Exit For
Next
Next
next
当前,TreeView项目的父映像可能为9,子映像可能为3
基于此,我想将所有具有图像索引3的项目添加到TreeView 2中,以匹配每个项目的父子部分
以下代码应该可以让您非常接近您想要的:
Dim objNode1 As Node
Dim objNode2 As Node
Dim objMatchNode As Node
Dim objChildNode1 As Node
Dim objChildNode2 As Node
Dim iCounter1 As Integer
Dim iCounter2 As Integer
Dim fFound As Boolean
On Error Resume Next
For Each objNode1 In TreeView1.Nodes
' Find matching node in Treeview2
For Each objNode2 In TreeView2.Nodes
If objNode2.Text = objNode1.Text Then
' Match found
Set objMatchNode = objNode2
Exit For
End If
Next
If Not objMatchNode Is Nothing Then
' Check all children
If objNode1.Children > 0 Then
' Get first Child
Set objChildNode1 = objNode1.Child
' Loop through all children
For iCounter1 = 1 To objNode1.Children
If objChildNode1.Image = 3 And objNode1.Image = 9 Then
' Check if it already exists in Treeview2
If objMatchNode.Children > 0 Then
' Get first Child
Set objChildNode2 = objMatchNode.Child
' Set Found flag to False
fFound = False
' Loop through all children
For iCounter2 = 1 To objMatchNode.Children
' Check for match
If objChildNode2.Text = objChildNode1.Text Then
fFound = True
Exit For
End If
' Get next node
Set objChildNode2 = objChildNode2.Next
Next
If Not fFound Then
' Add to Treeview2
TreeView2.Nodes.Add objMatchNode.Key, tvwChild, objChildNode1.Key, objChildNode1.Text, 3
End If
End If
End If
' Get next node
Set objChildNode1 = objChildNode1.Next
Next
End If
End If
' Give UI some time to do other things
DoEvents
Next
它完成了任务,只需要添加暂停,这样它就不会冻结。我的意思是不冻结的暂停。我完成了,只需要将它添加到添加参数的末尾。如果它回答了您的问题,请使用答案文本旁边的灰色复选标记将答案标记为已接受。是的,您回答了。我按下勾选按钮,它是绿色的,这是确定的,先生。是的,谢谢,非常感谢。当您遇到其他问题时,请返回堆栈溢出!