Skip to main content

Search

  • 9 minutes to read

The built-in Search Panel allows users to find information within the GridControl and TreeListControl:

Search Panel

The Search Panel searches data by display text.

Run Demo: Search Panel - Filter Mode Run Demo: Search Panel - Highlight Mode

View Example: WPF Data Grid - Create a Custom Search Window

Tip

The Data Grid supports AI-powered Semantic Search. Unlike standard keyword-based search, semantic search leverages Natural Language Processing (NLP) to analyze search queries beyond exact keyword matching. See the following help topic for additional information: Semantic Search AI-powered Extension.

Run Demo: Semantic Search - Grid Control

Show and Hide the Search Panel

To display the Search Panel, do one of the following:

To hide the Search Panel, do one of the following:

To move focus from the Search Panel to the grid’s data area, a user should press the Down Arrow key.

To show the MRU search drop-down list, a user should press Alt + Down Arrow keys.

Tip

Set the DataViewBase.ShowSearchPanelMode property to ShowSearchPanelMode.Always to always display the Search Panel.

Set the DataViewBase.ShowSearchPanelMode property to ShowSearchPanelMode.Never to prohibit users from displaying the Search Panel.

Filter and Highlight Results

You can specify how to display search results:

The GridControl raises filter events (FilterChanged, FilterGroupSortChanging, and so on) when users search data with the DataViewBase.SearchPanelAllowFilter option enabled.

The following table lists properties that affect highlighted text appearance:

Property Description
HighlightedTextBackground Gets or sets the brush used to paint the background of the highlighted text.
HighlightedTextForeground Gets or sets the brush used to paint the foreground of the highlighted text.
HighlightedFontSize Gets or sets the font size of the highlighted text.
HighlightedFontFamily Gets or sets the font family of the highlighted text.
HighlightedFontStyle Gets or sets the font style of the highlighted text.
HighlightedFontWeight Gets or sets the font weight of the highlighted text.
<dxg:GridColumn FieldName="ProductName">
    <dxg:GridColumn.EditSettings>
        <dxe:TextEditSettings>
            <dxe:TextEditSettings.StyleSettings>
                <dxe:TextEditStyleSettings HighlightedTextBackground="Orange" 
                                           HighlightedTextForeground="Red"/>
            </dxe:TextEditSettings.StyleSettings>
        </dxe:TextEditSettings>
    </dxg:GridColumn.EditSettings>
</dxg:GridColumn>

Search Panel UI

Search String

A user specifies a search string in the Search Panel‘s edit box. Use the DataViewBase.SearchString property to specify a search string in code.

Search Panel - Search String

Note

Searches performed with the Search Panel are case-insensitive.

Null Text

The text displayed in the Search Panel‘s edit box when the search text is null. Use the DataViewBase.SearchPanelNullText property to specify the null text.

Search Panel - NULL Text

Result Info Panel

Displays information about search results in the Search Panel. Set the DataViewBase.ShowSearchPanelResultInfo property to true to display the result info panel.

Search Panel - Result Info Panel

Note

The GridControl does not display the result info panel if the DataViewBase.SearchPanelAllowFilter property is set to true.

Allow users to navigate through search results. Set the DataViewBase.ShowSearchPanelNavigationButtons property to true to display navigation buttons in the Search Panel.

Search Panel Navigation Buttons

MRU Button

Allows users to invoke the MRU search drop-down list. Set the DataViewBase.ShowSearchPanelMRUButton property to true to display the MRU button in the Search Panel.

Search Panel MRU Button

The MRU search drop-down list displays the most recently used search strings. If the DataViewBase.SearchPanelImmediateMRUPopup property value is true, the MRU search drop-down is invoked when a user types in the Search Panel.

Find Button

The GridControl starts to search data after the delay that the DataViewBase.SearchDelay property specifies.

Set the DataViewBase.SearchPanelFindMode property to FindMode.FindClick to make the GridControl start to search data when a user presses Enter or clicks the Find button. To display the Find button in the Search Panel, set the DataViewBase.ShowSearchPanelFindButton property to true.

Search Panel Find Button

Close Button

Closes the Search Panel. Set the DataViewBase.ShowSearchPanelCloseButton property to false to hide the Close button.

Search Panel Close Button

Custom Content

You can place custom UI elements next to the search box. Assign a DataTemplate to the GridDataViewBase.SearchPanelLeftContentTemplate or GridDataViewBase.SearchPanelRightContentTemplate property to add elements (a label, icon, or button) to the left or right of the Search Panel.

Tip

The template’s DataContext returns the current view, so you can bind template elements directly to view properties.

<Window.Resources>
    <DataTemplate x:Key="SearchPanelRightTemplate">
        <Button Content="Clear" Command="{Binding ClearSearchCommand}"
                VerticalAlignment="Center" Margin="4,0,4,0"/>
    </DataTemplate>
</Window.Resources>

<dxg:GridControl.View>
    <dxg:TableView ShowSearchPanelMode="Always"
                   SearchPanelRightContentTemplate="{StaticResource SearchPanelRightTemplate}"/>
</dxg:GridControl.View>

Search Panel Positions

The Search Panel is merged with the Group Panel:

Search Panel Merged

Set the GridViewBase.SearchPanelPosition property to SearchPanelPosition.OverGroupPanel to show the Search Panel over the Group Panel:

Search Panel Over

You can specify the DataViewBase.SearchPanelHorizontalAlignment property to set the Search Panel‘s alignment. In the following image, the Search Panel is stretched:

Search Panel Stretch

Use the GridDataViewBase.SearchPanelMinWidth and GridDataViewBase.SearchPanelMaxWidth properties to constrain the Search Panel width to a specific range (in pixels). When a property is set to null, the corresponding limit depends on the current theme.

Search Syntax

  • Single keyword.

    Sales — Selects records that contain the “Sales” string in any search column.

    Search Panel Syntax - Single Keyword

  • To search for a string that contains a space character or another reserved character (+, -, %, :), specify this string in quotation marks.

    "Sales Manager" — Selects records that contain “Sales Manager” in any search column.

    Search Panel Syntax - Quotation Marks

  • Without quotation marks, words separated by the space character are treated as individual conditions.

    Sales Manager — Selects records that contain either “Sales” or “Manager” strings in any search column.

    Search Panel Syntax - Multiple Keywords

  • To search against a specific column, precede a search string with the column’s display name plus a colon character.

    Instead of the full name, you can specify only the initial characters of a column’s display name. The search runs against the first column whose display name starts with the specified substring. To search for a column whose display caption contains spaces, enclose the caption in quotation marks.

    Group:Sales — Selects records that contain “Sales” in the column that starts with “Group”.

    Search Panel Specific Column (Part 1)

    If the search string contains multiple conditions separated by spaces, and at least one condition targets a specific column, only records that match all conditions are displayed. In this case, the conditions are combined with the AND operator. If no condition targets a specific column, records that match at least one condition are displayed. In this case, the conditions are combined with the OR operator.

    Group:Sales Manager — Selects records that contain “Sales” in the column that starts with “Group”, and also contain “Manager” in any search column.

    Search Panel Specific Column (Part 2)

  • Precede a condition with + to display only records that match this condition. The + specifier allows you to implement the logical AND operator. There should be no space character between the + sign and the condition.

    Sales +Specialist — Selects records that contain both “Sales” and “Specialist” in search columns.

    Search Panel Syntax - AND Operator

  • Precede a condition with - to exclude records that match this condition from the result set. There should be no space between the - sign and the condition.

    Sales -Specialist — Selects records that contain “Sales” excluding records that contain “Specialist”.

    Search Panel Syntax - Minus Operator

    If the expression contains the - character, quotation marks are ignored.

  • (only if SearchPanelFindFilter is set to Like) Use the % character to apply the LIKE operator to the associated condition:

    Search Panel Syntax - Percent Operator

  • You can combine different operators.

    Sales +Representative -"United States" — Selects records that contain both “Sales” and “Representative” in search columns, excluding records that contain “United States”.

    Search Panel Syntax - Combine Operators

Parse Modes

Use the DataViewBase.SearchPanelParseMode property to specify how the search string is parsed.

Run Demo: Search Panel - Parse Modes

“And” (Default) Mode

Search words are combined by the AND operator:

Search Panel Parse Mode - AND

“Or” Mode

Search words are combined by the OR operator:

Search Panel Parse Mode - OR

To use the AND operator for a search word, add the + character before this word:

Search Panel Parse Mode -  OR With Plus

“Exact” Mode

The exact match. If the search string contains space characters, the words are not treated separately:

Search Panel Parse Mode - Exact

“Mixed” Mode

Search words are combined by the OR operator:

Search Panel Parse Mode - Mixed

The operator changes to AND if you specify a column name before a search word:

Search Panel Parse Mode - Mixed With Column

Tree List Filter Modes

The TreeListView displays only nodes that meet the filter criteria. A node at the highest hierarchy level that meets the filter criteria becomes the root node. The nearest child node that meets the filter criteria changes its hierarchy level to the next level down from the root.

Tree List Search Modes

You can change this behavior. Use the TreeListView.FilteringMode property to specify how to filter nodes.

Refer to the following help topic for more information: Filter Nodes.

SearchColumns Property

The DataViewBase.SearchColumns property specifies the field names against which searches are performed.

The default property value is *. In this case, a search is performed against all visible columns. To search against specific columns, specify the corresponding field names, delimiting them with the ; character. You can use the ColumnBase.AllowSearchPanel property to specify whether the column data is taken into account when using the Search Panel.

SearchPanelFindFilter Property

The DataViewBase.SearchPanelFindFilter property specifies the type of the comparison operator used to create filter conditions.

SearchStringToFilterCriteria Event

The DataViewBase.SearchStringToFilterCriteria event occurs when the GridControl starts to search data.

The following code sample configures the Search Panel to search for strings that contain spaces without requiring quotation marks:

Data Grid - SearchStringToFilterCriteria Event

<dxg:GridControl.View>
    <dxg:TableView
        SearchStringToFilterCriteria="TableView_SearchStringToFilterCriteria"
        SearchString="Alex Mercer"
        SearchPanelAllowFilter="False"/>
</dxg:GridControl.View>
void TableView_SearchStringToFilterCriteria(object sender, SearchStringToFilterCriteriaEventArgs e) {
    e.Filter = CriteriaOperator.Parse(string.Format("Contains([Name], '{0}')", e.SearchString));
}

Limitations

See Also