Skip to main content
A newer version of this page is available. .

ColumnView.QueryCustomFunctions Event

Allows you to add custom function based filters (for example, ‘discount is more than 15%’) to Excel-style pop-up filter menus and/or the filter editor.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v19.1.dll

Declaration

[DXCategory("Behavior")]
public event QueryCustomFunctionsEventHandler QueryCustomFunctions

Event Data

The QueryCustomFunctions event's data class is DevExpress.XtraGrid.Views.Grid.CustomFunctionEventArgs.

Remarks

To create a custom filter function (for example, ‘discount is more than 15%’), and add this function to Excel-style pop-up filter menus and/or the filter editor, do the following:

  • Implement a custom function.
  • Register the function.
  • Add the function to pop-up filter menus and the filter editor in a QueryCustomFunctions event handler.

The example below shows how to add the Black Friday Discount filter to a grid view.

Note

See the XtraGrid demo for the complete example.

using DevExpress.Data.Filtering;

IsBlackFridayDiscountFunction.Register();
gridView1.QueryCustomFunctions += OnQueryCustomFunctions;

void OnQueryCustomFunctions(object sender, CustomFunctionEventArgs e) {
    if(e.PropertyName == "Discount")
        e.Add(IsBlackFridayDiscountFunction.FunctionName);
}

public class IsBlackFridayDiscountFunction : ICustomFunctionDisplayAttributes {
    public const string FunctionName = "IsBlackFridayDiscount";
    static readonly IsBlackFridayDiscountFunction Instance = new IsBlackFridayDiscountFunction();
    IsBlackFridayDiscountFunction() { }
    public static void Register() {
        CriteriaOperator.RegisterCustomFunction(Instance);
    }
    public static bool Unregister() {
        return CriteriaOperator.UnregisterCustomFunction(Instance);
        }
    #region ICustomFunctionOperatorBrowsable Members
    public FunctionCategory Category {
        get { return FunctionCategory.Math; }
    }
    public string Description {
        get { return "The discount amount is 15% or more."; }
    }
    public bool IsValidOperandCount(int count) {
        return count == 1;
    }
    public bool IsValidOperandType(int operandIndex, int operandCount, Type type) {
        return DevExpress.Data.Summary.SummaryItemTypeHelper.IsNumericalType(type);
    }
    public int MaxOperandCount {
        get { return 1; }
    }
    public int MinOperandCount {
        get { return 1; }
    }
    #endregion
    #region ICustomFunctionDisplayAttributes
    public string DisplayName {
        get { return "Is Black Friday Discount"; }
    }
    public object Image {
        get { return "bo_price"; }
    }
    #endregion
    #region ICustomFunctionOperator Members
    public object Evaluate(params object[] operands) {
        double discount = Convert.ToDouble(operands[0]);
        return discount >= 0.15;
    }
    public string Name {
        get { return FunctionName; }
    }
    public Type ResultType(params Type[] operands) {
        return typeof(bool);
   }
    #endregion
}

In the case of a Code First data source, you can annotate data fields with the CustomFunction attribute.

[CustomFunction(IsBlackFridayDiscountFunction.FunctionName)]
public double Discount { get; set; }

Tip

To add custom functions to filter menus and filter editors of all DevExpress controls in the application, use the static (Shared in VB) QueryCustomFunctions event.

Warning

The QueryCustomFunctions event is not supported in server-side data source mode.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the QueryCustomFunctions 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.

See Also