all groups > vb.net controls > july 2005 >
You're in the

vb.net controls

group:

problem with Treeview diplicating nodes


problem with Treeview diplicating nodes ThunderMusic
7/18/2005 7:26:26 PM
vb.net controls: 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

Re: problem with Treeview diplicating nodes Ken Tucker [MVP]
7/19/2005 5:28:44 AM
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]
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


Re: problem with Treeview diplicating nodes ThunderMusic
7/19/2005 4:20:40 PM
thanks, it works fine. I don't what the other did that make the nodes
duplicate though.

Thanks a lot.

"Ken Tucker [MVP]" <vb2ae@bellsouth.net> a écrit dans le message de
news:uyfIFREjFHA.1428@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button