windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-b2638617.md
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.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[DXCategory("Data")]
public event EventHandler<SubstituteFilterEventArgs> SubstituteFilter
<DXCategory("Data")>
Public Event SubstituteFilter As EventHandler(Of SubstituteFilterEventArgs)
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. |
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.
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.
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();
}
}
Imports DevExpress.Data.Filtering
Imports DevExpress.Data
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Dim ds As New DataSet()
ds.ReadXml("nwind.xml")
Me.GridControl.DataSource = ds
Me.GridControl.DataMember = "Orders"
Me.GridView.ActiveFilterCriteria = CriteriaOperator.Parse("Freight > 0")
End Sub
Private Sub GridView_SubstituteFilter(ByVal sender As Object, ByVal e As SubstituteFilterEventArgs) Handles GridView.SubstituteFilter
e.Filter = e.Filter And CriteriaOperator.Parse("getyear(OrderDate) = ?", Convert.ToInt32(Me.beiShowByYear.EditValue))
End Sub
Private Sub beiShowByYear_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles beiShowByYear.EditValueChanged
Dim filter As CriteriaOperator = Me.GridView.ActiveFilterCriteria
Me.GridView.BeginDataUpdate()
Try
Me.GridView.ActiveFilterCriteria = Nothing
Me.GridView.ActiveFilterCriteria = filter
Finally
Me.GridView.EndDataUpdate()
End Try
End Sub
See Also