GUI/Controls/BetterTreeView.cs
/// <summary>
/// Performs a breadth-first-search on the TreeView's nodes in search of the passed value. The matching conditions are based on the passed search type parameter.
/// </summary>
/// <param name="value">Value to search for in the TreeView. Matching on this value is based on the search type.</param>
/// <param name="searchType">Determines the matching of the value. For example, full/partial text search or full path search.</param>
/// <returns>A collection of nodes who match the conditions based on the search type.</returns>
Performs a breadth-first-search on the TreeView's nodes in search of the passed value. The matching conditions are based on the passed search type parameter.
Performs a breadth - first - search on the TreeView ' s nodes in search of the passed value . The matching conditions are based on the passed search type parameter .
public IReadOnlyCollection<TreeNode> Search(string value, SearchType searchType)
        {
            IReadOnlyCollection<TreeNode> results = new List<TreeNode>().AsReadOnly();
            value = value.ToLower();
            if (searchType == SearchType.FileNameExactMatch)
            {
                results = Nodes.Find(value, true).ToList();
            }
            else if (searchType == SearchType.FileNamePartialMatch)
            {
                bool MatchFunction(TreeNode node) => node.Text.Contains(value);
                results = Search(MatchFunction);
            }
            else if (searchType == SearchType.FullPath)
            {
                value = value.Replace('\\', Package.DirectorySeparatorChar);
                bool MatchFunction(TreeNode node) => node.FullPath.Contains(value);
                results = Search(MatchFunction);
            }
            else if (searchType == SearchType.Regex)
            {
                var regex = new Regex(value, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
                bool MatchFunction(TreeNode node) => regex.IsMatch(node.Text);
                results = Search(MatchFunction);
            }
            return results;
        }
public IReadOnlyCollection < TreeNode > Search ( string value , SearchType searchType ) { IReadOnlyCollection < TreeNode > results = new List < TreeNode > ( ) . AsReadOnly ( ) ; value = value . ToLower ( ) ; if ( searchType == SearchType . FileNameExactMatch ) { results = Nodes . Find ( value , true ) . ToList ( ) ; } else if ( searchType == SearchType . FileNamePartialMatch ) { bool MatchFunction ( TreeNode node ) => node . Text . Contains ( value ) ; results = Search ( MatchFunction ) ; } else if ( searchType == SearchType . FullPath ) { value = value . Replace ( ' \\ ' , Package . DirectorySeparatorChar ) ; bool MatchFunction ( TreeNode node ) => node . FullPath . Contains ( value ) ; results = Search ( MatchFunction ) ; } else if ( searchType == SearchType . Regex ) { var regex = new Regex ( value , RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ) ; bool MatchFunction ( TreeNode node ) => regex . IsMatch ( node . Text ) ; results = Search ( MatchFunction ) ; } return results ; }
Performs a breadth-first-search on the TreeView's nodes in search of the passed value.
Performs a breadth - first - search on the TreeView ' s nodes in search of the passed value .
A collection of nodes who match the conditions based on the search type.
A collection of nodes who match the conditions based on the search type .
value
string
Value to search for in the TreeView. Matching on this value is based on the search type.
Value to search for in the TreeView . Matching on this value is based on the search type .
searchType
SearchType
Determines the matching of the value. For example, full/partial text search or full path search.
Determines the matching of the value . For example full / partial text search or full path search .