problem with Treeview diplicating nodes

T

ThunderMusic

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
 
K

Ken Tucker [MVP]

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

------------
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
 
T

ThunderMusic

thanks, it works fine. I don't what the other did that make the nodes
duplicate though.

Thanks a lot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top