Public Class Test
Dim CurrentNode As TreeNode
Private Sub Search_and_Add(CurrentNode As TreeNode, NodesListArray() As String, Pointer As Integer)
If Pointer >= NodesListArray.Length Then
Exit Sub
End If
Dim BasisNodeExists As Integer = 0
Dim BasisNodeGID As Integer = 0
If Pointer = 0 Then
For j As Integer = 0 To TreeView1.Nodes.Count - 1
If TreeView1.Nodes(j).Text = NodesListArray(j) Then
BasisNodeExists = 1
BasisNodeGID = j
End If
Next
If BasisNodeExists = 1 Then
Search_and_Add(TreeView1.Nodes.Item(BasisNodeGID), NodesListArray, Pointer + 1)
Else
TreeView1.Nodes.Add(New TreeNode(NodesListArray(Pointer)))
Search_and_Add(TreeView1.Nodes.Item(0), NodesListArray, Pointer + 1)
End If
Else
Dim NewEntryRequired As Integer = 1
For i As Integer = 0 To CurrentNode.Nodes.Count - 1
If CurrentNode.Nodes.Item(i).Text = NodesListArray(Pointer) Then
NewEntryRequired = 0
End If
Next
If NewEntryRequired = 1 Then
CurrentNode.Nodes.Add(New TreeNode(NodesListArray(Pointer)))
End If
For i As Integer = 0 To CurrentNode.Nodes.Count - 1
If CurrentNode.Nodes.Item(i).Text = NodesListArray(Pointer) Then
Search_and_Add(CurrentNode.Nodes.Item(i), NodesListArray, Pointer + 1)
End If
Next
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Search_and_Add(New TreeNode(), New String() {"1", "2", "3"}, 0)
End Sub
End Class