GridControl.SubstituteFilter Event
Allows you to replace a filter applied with another filter.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v24.2.dll
NuGet Package: DevExpress.Wpf.Grid.Core
#Declaration
public event EventHandler<SubstituteFilterEventArgs> SubstituteFilter
#Event Data
The SubstituteFilter event's data class is SubstituteFilterEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Filter | Gets or sets the filter applied to a data control. |
#Remarks
The currently applied filter is specified by the Filter event parameter. To replace this filter, assign a new filter criterion to this parameter.
The following code sample demonstrates how to handle the SubstituteFilter
event to filter grid values that include diacritic characters:
using DevExpress.Data.Filtering;
using DevExpress.Data.Filtering.Helpers;
using System;
using System.Globalization;
using System.Linq;
using System.Text;
namespace DXSample {
public partial class MainWindow {
public MainWindow() {
InitializeComponent();
}
static MainWindow() {
CriteriaOperator.RegisterCustomFunction(new CustomOperator());
}
private void grid_SubstituteFilter(object sender, DevExpress.Data.SubstituteFilterEventArgs e) {
e.Filter = CustomPatcher.Patch(e.Filter);
}
}
public class CustomPatcher : ClientCriteriaLazyPatcherBase.AggregatesCommonProcessingBase {
private CustomPatcher() { }
public static CriteriaOperator Patch(CriteriaOperator source) {
return new CustomPatcher().Process(source);
}
public override CriteriaOperator Visit(FunctionOperator theOperator) {
if (theOperator.OperatorType == FunctionOperatorType.Contains
&& theOperator.Operands[0] is OperandProperty property
&& theOperator.Operands[1] is OperandValue value
&& value.Value is string)
return new FunctionOperator(FunctionOperatorType.Contains,
new FunctionOperator("RemoveDiacriticsCustom", new OperandProperty(property.PropertyName)),
new FunctionOperator("RemoveDiacriticsCustom", new OperandValue(value.Value)));
return base.Visit(theOperator);
}
}
public class CustomOperator : ICustomFunctionOperator {
string ICustomFunctionOperator.Name { get { return "RemoveDiacriticsCustom"; } }
private static string RemoveDiacriticsCustom(string text) {
return string.Concat(text.Normalize(NormalizationForm.FormD).Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) != UnicodeCategory.NonSpacingMark)).Normalize(NormalizationForm.FormC);
}
object ICustomFunctionOperator.Evaluate(params object[] operands) {
if (operands.Length == 1 && operands[0] is string value)
return RemoveDiacriticsCustom(value);
return null;
}
Type ICustomFunctionOperator.ResultType(params Type[] operands) {
return typeof(string);
}
}
}
Do not modify the existing filter object assigned to the Filter event parameter.
Refer to the following help topic for more information on criteria patchers: Traverse Through and Modify the CriteriaOperator Instances.
#Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SubstituteFilter 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.