Back to Devexpress

ColumnView.SubstituteFilter Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-b2638617.md

latest4.4 KB
Original Source

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.v25.2.dll

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

Declaration

csharp
[DXCategory("Data")]
public event EventHandler<SubstituteFilterEventArgs> SubstituteFilter
vb
<DXCategory("Data")>
Public Event SubstituteFilter As EventHandler(Of SubstituteFilterEventArgs)

Event Data

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

PropertyDescription
FilterGets 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.

csharp
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();
    }
}
vb
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

View Example

See Also

ColumnView Class

ColumnView Members

DevExpress.XtraGrid.Views.Base Namespace