curiousvbnet
Programmer
Hi,
i have created a sub which permits to recover a same node in a treeiew if this one exists at several places in the treeview.
By this sub i can recover the number of times this nodes exists in the treeview but not the nodes themselves .
How can i recover all the nodes of this same node.
for example : if i search the term 'search organism' in a treeview called treeview1 , this term exists at several places in the treeview but at each place its parent node is not the same.
So how can find all the nodes of this term.
Here is the code i use until now
i have created a sub which permits to recover a same node in a treeiew if this one exists at several places in the treeview.
By this sub i can recover the number of times this nodes exists in the treeview but not the nodes themselves .
How can i recover all the nodes of this same node.
for example : if i search the term 'search organism' in a treeview called treeview1 , this term exists at several places in the treeview but at each place its parent node is not the same.
So how can find all the nodes of this term.
Here is the code i use until now
Code:
[blue]Private Function Findnodescountintreeview(ByVal TagNode As String, ByVal Nodes As TreeNodeCollection) As Integer [/blue]
Dim nNode As TreeNode, nResult As TreeNode
Dim nFoundNode As TreeNode = Nothing
Dim strTag As String, strTag_pref As String, iTagVal As Integer
Dim compte_noeud_cherche As Integer = 0
[green] 'Check to see if a node with the specified Tag exists in the current Nodes collection [/green]
For Each nNode In Nodes
strTag = CType(nNode.Tag, String)
[green] 'the iTagVal value is the one after the two letters 'GT' or 'MT' [/green]
iTagVal = CType(strTag.Substring(2), Integer)
If nNode.Tag = strTag Then
nFoundNode = nNode
compte_noeud_cherche = compte_noeud_cherche + 1
Else
[green] ' If we haven't found the node we were looking at check the nodes collection of all the Nodes in the current collection... [/green]
compte_noeud_cherche = nodescountintreeview(TagNode, nNode.Nodes)
End If
Next
If Not nFoundNode Is Nothing Then
Return compte_noeud_cherche
End If 'fin de If Not nFoundNode Is Nothing
End Function
Hereis the sub i use until now to fin a node which exists only once in the treeview
[code]
[blue]Private Function FindNode(ByVal iTermeID As Integer, ByVal Nodes As TreeNodeCollection) As TreeNode [/blue]
Dim nNode As TreeNode, nResult As TreeNode
Dim nFoundNode As TreeNode = Nothing
Dim strTag As String, iTagVal As Integer
[green] 'Check to see if a node with the specified Tag exists in the current Nodes collection [/green]
For Each nNode In Nodes
strTag = CType(nNode.Tag, String)
'la valeur du tag est celle qui suit les deux caractères "GT" ou "MT"
iTagVal = CType(strTag.Substring(2), Integer)
'strTag value is "GT " or "MT ", whch are the two first characters of the tag
strTag = strTag.Substring(0, 2)
If strTag = "GT" And iTagVal = iTermeID Then
nFoundNode = nNode
Exit For
' [green] ' If we haven't found the node we were looking at check the nodes collection of all the Nodes in the current collection... [/green]
nFoundNode = FindNode(iTermeID, nNode.Nodes)
If Not nFoundNode Is Nothing Then Exit For
End If
Next
Return nFoundNode
End Function
[code]
Thanks a lot for your help.
Best Regards
Nathalie