TreeView Control: Highlight Multiple Nodes?

by Mel on 11/1/2007 12:04:00 AM I have a treeview control that contains a list of filenames which I am
searching. If a file in the tree matches the search criteria the
entire node is expanded. Often times there are other files in that
expanded node that don't match the criteria. Is there a way to
highlight ALL the nodes that matched the search criteria?


Example Code (Using ASP.NET 2.0, Visual Basic):
    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click 'THIS IS MY SEARCH BUTTON
        Dim find As Boolean = False
        tvDocs.CollapseAll()
        Search(txtSearch.Text, tvDocs.Nodes(0), find) 'FIND THE
SEARCH CRITERIA IN THE TREE
        If find = True Then tvDocs.Nodes(0).Expand()

    End Sub

    Protected Sub Search(ByVal key As String, ByVal n As TreeNode,
ByRef find As Boolean)
        Dim child As TreeNode
        For Each child In n.ChildNodes
            If (child.Text.ToLower().StartsWith(key.ToLower())) Then
                ExpandParent(child)
                child.Selected = True 'WHEN THIS LOOP FINISHES ONLY
THE LAST NODE IS HIGHLIGHTED!
                find = True
            End If
            Search(key, child, find)
        Next
    End Sub

    Protected Sub ExpandParent(ByVal n As TreeNode)
        n.Expand()
        If (Not n.Parent Is Nothing) Then
            ExpandParent(n.Parent)
        End If
    End Sub