The event handler receives an argument of type DevExpress.XtraTreeList.CustomFunctionEventArgs containing data related to this event.
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:
The example below shows how to add the Black Friday Discount filter to a grid view.

Note
See the XtraGrid demo and click Open Solution for the complete example.
C# |
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
}
|
VB |
Imports DevExpress.Data.Filtering
IsBlackFridayDiscountFunction.Register()
AddHandler gridView1.QueryCustomFunctions, AddressOf OnQueryCustomFunctions
Private Sub OnQueryCustomFunctions(ByVal sender As Object, ByVal e As Data.Filtering.CustomFunctionEventArgs)
If e.PropertyName = "Discount" Then
e.Add(IsBlackFridayDiscountFunction.FunctionName)
End If
End Sub
Public Class IsBlackFridayDiscountFunction
Implements ICustomFunctionDisplayAttributes
Public Const FunctionName As String = "IsBlackFridayDiscount"
Private Shared ReadOnly Instance As New IsBlackFridayDiscountFunction()
Private Sub New()
End Sub
Public Shared Sub Register()
CriteriaOperator.RegisterCustomFunction(Instance)
End Sub
Public Shared Function Unregister() As Boolean
Return CriteriaOperator.UnregisterCustomFunction(Instance)
End Function
#Region "ICustomFunctionOperatorBrowsable Members"
Public ReadOnly Property Category() As FunctionCategory Implements DevExpress.Data.Filtering.ICustomFunctionOperatorBrowsable.Category
Get
Return FunctionCategory.Math
End Get
End Property
Public ReadOnly Property Description() As String Implements DevExpress.Data.Filtering.ICustomFunctionOperatorBrowsable.Description
Get
Return "The discount amount is 15% or more."
End Get
End Property
Public Function IsValidOperandCount(ByVal count As Integer) As Boolean Implements DevExpress.Data.Filtering.ICustomFunctionOperatorBrowsable.IsValidOperandCount
Return count = 1
End Function
Public Function IsValidOperandType(ByVal operandIndex As Integer, ByVal operandCount As Integer, ByVal type As Type) As Boolean Implements DevExpress.Data.Filtering.ICustomFunctionOperatorBrowsable.IsValidOperandType
Return DevExpress.Data.Summary.SummaryItemTypeHelper.IsNumericalType(type)
End Function
Public ReadOnly Property MaxOperandCount() As Integer Implements DevExpress.Data.Filtering.ICustomFunctionOperatorBrowsable.MaxOperandCount
Get
Return 1
End Get
End Property
Public ReadOnly Property MinOperandCount() As Integer Implements DevExpress.Data.Filtering.ICustomFunctionOperatorBrowsable.MinOperandCount
Get
Return 1
End Get
End Property
#EndRegion
#Region "ICustomFunctionDisplayAttributes"
Public ReadOnly Property DisplayName() As String Implements ICustomFunctionDisplayAttributes.DisplayName
Get
Return "Is Black Friday Discount"
End Get
End Property
Public ReadOnly Property Image() As Object Implements ICustomFunctionDisplayAttributes.Image
Get
Return "bo_price"
End Get
End Property
#EndRegion
#Region "ICustomFunctionOperator Members"
Public Function Evaluate(ParamArray ByVal operands() As Object) As Object Implements DevExpress.Data.Filtering.ICustomFunctionOperator.Evaluate
Dim discount As Double = Convert.ToDouble(operands(0))
Return discount >= 0.15
End Function
Public ReadOnly Property Name() As String Implements DevExpress.Data.Filtering.ICustomFunctionOperator.Name
Get
Return FunctionName
End Get
End Property
Public Function ResultType(ParamArray ByVal operands() As Type) As Type Implements DevExpress.Data.Filtering.ICustomFunctionOperator.ResultType
Return GetType(Boolean)
End Function
#EndRegion
End Class
|
In the case of a Code First data source, you can annotate data fields with the CustomFunction
attribute.
C# |
[CustomFunction(IsBlackFridayDiscountFunction.FunctionName)]
public double Discount { get; set; }
|
VB |
<CustomFunction(IsBlackFridayDiscountFunction.FunctionName)>
Public Property Discount() As Double
|