Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
# How to search and highlight item in TreeViewAdv?
This example demonstrates how to search and highlighted the item of TreeViewAdv control in WPF platform.
# How to search and highlight items in WPF TreeViewAdv?

# About Sample
In [WPF TreeViewAdv](https://help.syncfusion.com/wpf/classic/treeview/overview) 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](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Tools.Controls.TreeViewItemAdv.html).

This sample provides the demo on how to search and highlight the text in TreeViewAdv.
```csharp
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.

```csharp
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](SearchandHighlight.png)
Binary file added SearchandHighlight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.