TreeView Control: Highlight Multiple Nodes?

M

Mel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top