Skip to main content

DataViewBase.SearchStringToFilterCriteria Event

Occurs each time the GridControl starts to search data and allows you to convert the search string to filter criteria.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v23.2.Core.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public event SearchStringToFilterCriteriaEventHandler SearchStringToFilterCriteria

Event Data

The SearchStringToFilterCriteria event's data class is SearchStringToFilterCriteriaEventArgs. The following properties provide information specific to this event:

Property Description
ApplyToColumnsFilter Gets or sets whether the column’s filter popup detects changes in the search panel.
Filter Gets or sets the filter that is applied to the GridControl.
Highlighting Gets or sets highlighting strings for fields.
SearchString Gets the search string entered in the Search Panel.
Source Gets the GridControl.

Remarks

The following code sample shows how to make the Search Panel search for a string that contains a space character without the need to specify this string in 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));
}

Note

If you handle the SearchStringToFilterCriteria event and do not specify the SearchStringToFilterCriteriaEventArgs.Filter property, the GridControl does not search items.

When you assign complex filter criteria to the e.Filter property, the GridControl may not highlight search results. In this case, specify the e.Highlighting property:

private void TableView_SearchStringToFilterCriteria(object sender, DevExpress.Xpf.Grid.SearchStringToFilterCriteriaEventArgs e) {
    e.Filter = CriteriaOperator.Parse(string.Format("Contains([Name], '{0}') OR Contains([Id], '{0}')", e.SearchString));
    e.Highlighting = new List<FieldAndHighlightingString>((sender as TableView).VisibleColumns.Select(c => new FieldAndHighlightingString(c.FieldName, e.SearchString)));
}

Refer to the following help topic for more information: Search.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SearchStringToFilterCriteria event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also