DevExpress-Examples / winforms-grid-introduce-custom-options-in-auto-filter-row

Implement new filter options in the Auto Filter Row.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WinForms Data Grid - Implement new filter options in the Auto Filter Row

This example creates a custom grid control (MyGridControl) to introduce new filter options. Users can use the following operands to filter DateTime values in columns using the Auto Filter Row: "<", ">", ">=", "<=".

See the implementation of the GridView.CreateAutoFilterCriterion method:

protected override DevExpress.Data.Filtering.CriteriaOperator CreateAutoFilterCriterion(DevExpress.XtraGrid.Columns.GridColumn column, DevExpress.XtraGrid.Columns.AutoFilterCondition condition, object _value, string strVal) {
    if (column.ColumnType == typeof(DateTime) && strVal.Length > 0) {
        BinaryOperatorType type = BinaryOperatorType.Equal;
        string operand = string.Empty;
        if (strVal.Length > 1) {
            operand = strVal.Substring(0, 2);
            if (operand.Equals(">="))
                type = BinaryOperatorType.GreaterOrEqual;
            else if (operand.Equals("<="))
                type = BinaryOperatorType.LessOrEqual;
        }
        if (type == BinaryOperatorType.Equal) {
            operand = strVal.Substring(0, 1);
            if (operand.Equals(">"))
                type = BinaryOperatorType.Greater;
            else if (operand.Equals("<"))
                type = BinaryOperatorType.Less;
        }
        if (type != BinaryOperatorType.Equal) {
            string val = strVal.Replace(operand, string.Empty);
            try {
                DateTime dt = DateTime.ParseExact(val, "d", column.RealColumnEdit.EditFormat.Format);
                return new BinaryOperator(column.FieldName, dt, type);
            }
            catch {
                return null;
            }
        }
    }
    return base.CreateAutoFilterCriterion(column, condition, _value, strVal);
}

Files to Review

Documentation

See Also

About

Implement new filter options in the Auto Filter Row.

License:Other


Languages

Language:C# 56.2%Language:Visual Basic .NET 43.8%