Вы можете сделать узлы поиска, установив его name/key.
' key text
albumNode.Nodes.Add("Song", "Name of song 1")
albumNode.Nodes.Add("Song", "Name of song 2")
albumNode.Nodes.Add("Song", "Name of song 3")
Чтобы найти все узлы с ключом "Песня":
Dim songNodes As TreeNode() = myTreeView.Nodes.Find("Song", searchAllChildren:=True)
Вот пример:
Using view As New TreeView
For i As Integer = 1 To 2
'Add a new artist node with the key "Artist"
With view.Nodes.Add("Artist", String.Format("Artist {0}", i))
Debug.WriteLine(.Text)
For j As Integer = 1 To 2
'Add a new album node with the key "Album"
With .Nodes.Add("Album", String.Format("Album {0}-{1}", i, j))
Debug.WriteLine(" " & .Text)
For k As Integer = 1 To 3
'Add a new song node with the key "Song"
With .Nodes.Add("Song", String.Format("Song {0}-{1}-{2}", i, j, k))
Debug.WriteLine(" " & .Text)
End With
Next
End With
Next
End With
Next
Debug.WriteLine("")
Debug.WriteLine("Nodes with ""Song"" key:")
Debug.WriteLine("")
For Each node As TreeNode In view.Nodes.Find("Song", searchAllChildren:=True)
Debug.WriteLine(node.Text)
Next
End Using
Вывод в окне Immediate:
Artist 1
Album 1-1
Song 1-1-1
Song 1-1-2
Song 1-1-3
Album 1-2
Song 1-2-1
Song 1-2-2
Song 1-2-3
Artist 2
Album 2-1
Song 2-1-1
Song 2-1-2
Song 2-1-3
Album 2-2
Song 2-2-1
Song 2-2-2
Song 2-2-3
Nodes with "Song" key:
Song 1-1-1
Song 1-1-2
Song 1-1-3
Song 1-2-1
Song 1-2-2
Song 1-2-3
Song 2-1-1
Song 2-1-2
Song 2-1-3
Song 2-2-1
Song 2-2-2
Song 2-2-3