Farbschema: Hell
Sie befinden sich hier: start » en » Documentation » Microsoft Access development tools » WKL Forms Object Library » WKL Forms Object Library how-to guides » How to: Search and filter nodes

How to: Search and filter nodes

Find nodes by their text, select them one after another, and limit the tree to the nodes that match a condition.

Requires WKL Forms Object Library 1.23 or later.

Solution overview

SearchText highlights every node whose text contains the search text, and FindNext selects the matches one by one; users can do the same in the search bar (Ctrl+F, AllowSearch). Filter hides every node except those that match a WHERE condition or a JPath expression, along with their ancestors. SelectNode and NodeExists find a single node by its path.

Implementation

With Me!Tree1.Object
    .SearchText = "Ca"                   ' highlights matches, loaded or not
    Debug.Print .SearchCount & " matches"
    .FindNext                            ' selects the next match; .FindNext True: previous
    .SearchText = ""                     ' ends the search
 
    .Filter = "Active = True"            ' WHERE condition of the record source, like Form.Filter
    .Filter = "$..[?(@.Checked == true)]" ' or JPath over the loaded nodes
    .Filter = ""                         ' shows everything, view as before the filter
 
    If .NodeExists("United States\Texas") Then .SelectNode "United States\Texas"
    Debug.Print UBound(.FindNodes("$..[?(@.Level == 2)]")) + 1 & " nodes on level 2"
End With

Remarks

  • The search counts up to 1,000 matches. It queries the record source (LIKE '*text*' on TextField) unless the whole tree is loaded (LazyLoad = False or GroupFields), in which case it scans the loaded nodes.
  • A WHERE filter queries the record source every time you set it; with a pass-through query, the whole query runs on the server.
  • Text path comparisons are case-insensitive and use PathSeparator (backslash by default). With LazyLoad, only the levels along the path are loaded.
  • JPath runs over a JSON view in which each node has Key, Text, ParentKey, Image, SortValue, Checked, Level, and Nodes; FindNodes loads the whole tree first.
  • In the search bar, F3 and Shift+F3 move between matches, Enter selects the next one, and Matches only filters the tree to the matches.
en/wiki/msaccess/comctl/how-to/search-and-filter.txt · Zuletzt geändert: von Wolfgang van der Stille