我正在动态填充树视图,所以我不知道我可能拥有的级别数量。
有没有办法回滚到上一个级别?这是我的代码示例:
Private Sub RecursiveTreeAssembly(FileName As String, node As TreeNodeCollection)
'Sets sFileNamePath to correct path value
FileNameToFilePath(FileName)
'Start SolidEdge
StartSolidEdge()
'Open document
OpenSolidEdgeDocument(sFileNamePath)
'Get the parts list for the opened document (FileName)
partList = clsPartInformation.GetAll()
'Populate tree View
If partList.Count > 0 Then
'PartsList retrieved, close document
CloseSolidEdgeDocument(FileName)
'Go through all part lists and display them in tree view
For i As Integer = 0 To partList.Count - 1
'Is it Assembly, Parametric, Material, Part to buy
If IsAssembly(partList(i).Part_No) Then
node(iterator).Nodes.Add(partList(i).Part_No)
ElseIf IsMaterial(partList(i).Part_No) Then
node(iterator).Nodes.Add(partList(i).Part_No)
ElseIf IsPart(partList(i).Part_No) Then
node(iterator).Nodes.Add(partList(i).Part_No)
End If
tvDessins.ExpandAll()
Next
End If
'Go through tree view to populate it
While iterator < tvDessins.Nodes(0).Nodes.Count
If rollback Then
node = tvDessins.Nodes
currFileName = node(0).Nodes.Item(iterator).Text
Else
currFileName = node(iterator).Nodes.Item(0).Text
End If
If IsAssembly(currFileName) Then
rollback = False
'Call itself again
RecursiveTreeAssembly(currFileName, node(0).Nodes)
Else
'Rollback nodes
rollback = True
End If
iterator += 1
End While
End Sub
tvDessin 是我的树视图。在下面的代码中,我将遍历一个树视图,该树视图已经递归地给出了一些项目。我的零件清单包含零件号,效果很好。
在回滚期间,我将树节点设置为开头: node = tvDessins.Nodes
而不是简单地转到父节点......这就是我想要实现的!
谢谢,抱歉发了这么长的帖子。