Skip to content

SyncfusionExamples/How-to-search-and-highlight-the-item-in-TreeViewAdv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to search and highlight items in WPF TreeViewAdv?

In WPF TreeViewAdv to search and highlight the item, Search method has been implemented which is used to compare the search text with model items and highlighted the matched text in TextBlock inside the TreeViewItemAdv.

if (mainitem != null && MatchSearchText(model.Header))
{
    // Function which is used to apply inline to the TextBlock
    ApplyInline(mainitem, false);
}

Options like Search, FindPrevious, Find Next, SearchType (Contains, EndsWith, StartsWith options) has been used to match search text using ApplyInline method and apply the SearchBrush for highlighting the search text.

if (!string.IsNullOrEmpty(tempSearchText))
{
    if (this.SearchType == SearchType.StartsWith)
    {
        if (!(bool)CaseSensitiveSearchCheckBox.IsChecked)
            regex = new Regex("^(" + tempSearchText + ")", RegexOptions.IgnoreCase);
        else
            regex = new Regex("^(" + tempSearchText + ")", RegexOptions.None);
    }
    else if (this.SearchType == SearchType.EndsWith)
    {
        if (!(bool)CaseSensitiveSearchCheckBox.IsChecked)
            regex = new Regex("(" + tempSearchText + ")$", RegexOptions.IgnoreCase);
        else
            regex = new Regex("(" + tempSearchText + ")$", RegexOptions.None);
    }
    else
    {
        if (!(bool)CaseSensitiveSearchCheckBox.IsChecked)
            regex = new Regex("(" + tempSearchText + ")", RegexOptions.IgnoreCase);
        else
            regex = new Regex("(" + tempSearchText + ")", RegexOptions.None);
    }   
}

The following screenshot illustrates how to highlight and perform search in TreeViewAdv.

Search and highlight item

About

This repository contains the article about search and highlight the item in TreeViewAdv.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 6

Languages