Hi,
Here is an example I made to search for a node and change its
text.
FindNodes(trvNorthWind.Nodes, "Robert King", "Ken Tucker")
Private Sub FindNodes(ByVal node As TreeNodeCollection, ByVal FindText As
String, _
ByVal NewText As String)
Dim tn As TreeNode
For Each tn In node
If tn.Text = FindText Then
tn.Text = NewText
End If
FindNodes(tn.Nodes, FindText, NewText)
Next
End Sub
Ken
------------
[quoted text, click to view] "ThunderMusic" <NOdanylat@sympatico.caSPAMATALL> wrote in message
news:%23oSjZ%23%23iFHA.2644@TK2MSFTNGP09.phx.gbl...
Hi,
while I'm searching into a treeview to find a specific node, I find the
code duplicating treeview nodes I just can't figure out what's causing this
behavior, maybe some of you already encountered this problem. Can someone
help please?
Here is the code of the functions causing this problem
Thanks
ThunderMusic
Private Function FindTVNode(ByVal Path As String) As TreeNode
Dim FoundNode As TreeNode
Dim Cpt As Integer
Dim Found As Boolean
Found = False
Cpt = 0
Do While (Not Found) And Cpt < TVAll.GetNodeCount(False)
If TVAll.Nodes.Item(Cpt).FullPath = Path Then
FoundNode = TVAll.Nodes.Item(Cpt)
Found = True
Else
FoundNode = FindTVNodeRec(TVAll.Nodes.Item(Cpt), Path)
If FoundNode Is Nothing Then
Cpt += 1
Else
Found = True
End If
End If
Loop
FindTVNode = FoundNode
End Function
Private Function FindTVNodeRec(ByRef Node As TreeNode, ByVal Path As String)
As TreeNode
Dim FoundNode As TreeNode
Dim Cpt As Integer
Dim Found As Boolean
FoundNode = Nothing
Cpt = 0
Found = False
Do While Not (Found) And Cpt < Node.GetNodeCount(False)
If Node.Nodes.Item(Cpt).FullPath = Path Then
FoundNode = Node.Nodes.Item(Cpt)
Found = True
Else
FoundNode = FindTVNodeRec(TVAll.Nodes.Item(Cpt), Path)
If FoundNode Is Nothing Then
Cpt += 1
Else
Found = True
End If
End If
Loop
FindTVNodeRec = FoundNode
End Function