TreeView Control: Highlight Multiple Nodes?

Discussion in 'ASP .Net' started by Mel, Nov 1, 2007.

  1. Mel

    Mel Guest

    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
     
    Mel, Nov 1, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. asd
    Replies:
    3
    Views:
    461
    Arnaud Berger
    May 23, 2005
  2. gavnosis
    Replies:
    0
    Views:
    548
    gavnosis
    Aug 2, 2003
  3. th3dude
    Replies:
    0
    Views:
    452
    th3dude
    Jan 3, 2007
  4. Per Salmi

    TreeView not rendering nodes? Cacheing of a TreeView

    Per Salmi, Oct 15, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    520
    Steve Drake
    Oct 15, 2003
  5. Mark Goldin

    Highlight node in TreeView

    Mark Goldin, Feb 16, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    120
    Mark Goldin
    Feb 16, 2004
Loading...

Share This Page