Skip to main content

ColumnView.SubstituteFilter Event

Allows you to update or replace the filter that is about to be applied with a custom filter.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v24.1.dll

NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

[DXCategory("Data")]
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 SubstituteFilter event fires when a new filter is about to be applied to the data. The event allows you to update or replace the filter with a custom filter.

The Filter event argument gets or sets an object that specifies the filter that is about to be applied. To replace or update this filter, assign a new object to this argument or use the logical AND operator to combine the existing object with the new object. Do not modify the existing filter object.

Example

The code below shows how to handle the SubstituteFilter event to update the filter applied in the grid with a filter selected in a combo box.

image

using DevExpress.Data.Filtering;
using DevExpress.Data;

private void Form1_Load(object sender, EventArgs e) {
    DataSet ds = new DataSet();
    ds.ReadXml("nwind.xml");
    this.GridControl.DataSource = ds;
    this.GridControl.DataMember = "Orders";
    this.GridView.ActiveFilterCriteria = CriteriaOperator.Parse("Freight > 0");
}

private void GridView_SubstituteFilter(object sender, SubstituteFilterEventArgs e) {
    e.Filter &= CriteriaOperator.Parse("getyear(OrderDate) = ?", Convert.ToInt32(this.beiShowByYear.EditValue));
}

private void beiShowByYear_EditValueChanged(object sender, EventArgs e) {
    CriteriaOperator filter = this.GridView.ActiveFilterCriteria;
    this.GridView.BeginDataUpdate();
    try {
        this.GridView.ActiveFilterCriteria = null;
        this.GridView.ActiveFilterCriteria = filter;
    } finally {
        this.GridView.EndDataUpdate();
    }
}

View Example

See Also