curiousvbnet
Programmer
I have created a sub wich permits to find a node in a treeview.
A user clicks on an item in the ListView1 and the node which corresponds to this item's tag appears in color blue in the TreeView1
But if this same node exists several times in the treeview, how can i recover all the places in the treeview where
it is.
For the moment the sub code is this one
Thanks a lot for your help and advices.
Best regards.
Nathalie
A user clicks on an item in the ListView1 and the node which corresponds to this item's tag appears in color blue in the TreeView1
But if this same node exists several times in the treeview, how can i recover all the places in the treeview where
it is.
For the moment the sub code is this one
Code:
[blue]Private Sub ListView1_ItemActivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.ItemActivate[/blue]
Dim iSelectedTermeID As Integer, strLibTerme As String, id_mt As Integer
'déclaration de deux arrays qui vont contenir plusieurs lignes
Dim drNAs() As DataRow, drSyns() As DataRow, drNA As DataRow, drSYN As DataRow
Dim nNANode As TreeNode, nSynNode As TreeNode
If Not ListView1.FocusedItem Is Nothing AndAlso Not ListView1.FocusedItem.Tag Is Nothing Then
ListView1.FocusedItem.ForeColor = SystemColors.HighlightText.Magenta
iSelectedTermeID = CType(ListView1.FocusedItem.Tag, Integer)
strLibTerme = ListView1.SelectedItems(0).Text
[green] ' search the node in the TreeView1[/green]
nNode1 = FindNode(iSelectedTermeID, TreeView1.Nodes)
If Not nNode1 Is Nothing Then
TreeView1.SelectedNode = nNode1
If Not TreeView1.SelectedNode Is Nothing Then
[blue] With nNode1
.BackColor = SystemColors.Highlight.DeepSkyBlue
.ForeColor = SystemColors.HighlightText.MediumSlateBlue
End With[/blue]
nNode1.ExpandAll()
End If ' fin de If Not TreeView1.SelectedNode Is Nothing
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
'Check to see if a node with the specified Tag exists in the current Nodes collection
For Each nNode In Nodes
strTag = CType(nNode.Tag, String)
[green] the tag value is the one after the two letters "GT" ou "MT"[/green]
iTagVal = CType(strTag.Substring(2), Integer)
'strTag est égale aux deux lettres "GT " ou "MT ", qui sont les deux premiers caractères du tag
strTag = strTag.Substring(0, 2)
If strTag = "GT" And iTagVal = iTermeID Then
nFoundNode = nNode
Exit For
' 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]
nFoundNode = FindNode(iTermeID, nNode.Nodes)
If Not nFoundNode Is Nothing Then Exit For
End If
Next
Return nFoundNode
End Function
Thanks a lot for your help and advices.
Best regards.
Nathalie