All docs
V21.1
21.2 (EAP/Beta)
21.1
20.2
The page you are viewing does not exist in version 20.2. This link will take you to the root page.
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Custom Functions in the Expression Editor (WinForms)

  • 3 minutes to read

Create a Custom Function (WinForms Report Designer)

To create a custom function, create an object that descends from the ReportCustomFunctionOperatorBase abstract class.

The following code defines a custom function in the String category:

using DevExpress.XtraReports.Expressions;
using System;
// ...
    public class CustomFormatFunction : ReportCustomFunctionOperatorBase
    {
        public override string FunctionCategory 
            => "String";
        public override string Description 
            => "CustomFormatFunction(string format, object arg0)" +
            "\r\nConverts an arg0 value to a string based on a specified format";
        public override bool IsValidOperandCount(int count) 
            => count == 2;
        public override bool IsValidOperandType(int operandIndex, int operandCount, Type type) 
            => true;
        public override int MaxOperandCount
            => 2;
        public override int MinOperandCount
            => 2;
        public override object Evaluate(params object[] operands)
        {
            string res = String.Format(operands[0].ToString(), operands[1]);
            return res;
        }
        public override string Name 
            => "CustomFormatFunction";
        public override Type ResultType(params Type[] operands)
        {
            return typeof(string);
        }
    }

Call the static CustomFunctions.Register method to register a custom function. Pass the custom function class instance as a parameter. To unregister a custom function, use the static CustomFunctions.Unregister method.

The following code registers a custom function for use in the End-User Designer:

private void Form1_Load(object sender, EventArgs e)
{
// ...
    DevExpress.XtraReports.Expressions.CustomFunctions.Register(new CustomFormatFunction());
    // ...
    reportDesigner1.OpenReport(new Reports.XtraReport1());
}

The Expression Editor displays the CustomFormatFunction in the String category:

Expression Editor Custom Function

Custom functions registered in the Form constructor are available only in the Report Designer on the form. They are not available in the Visual Studio Report Designer. You can proceed without the Expression Editor and use the Property Grid editor to type a custom function in an expression.

Remove a Function from the List of Available Functions

Review the following help topic for more information: Remove a Function from the Expression Editor

Unregister a Function

If you remove a function from the list of available functions, the function remains recognized, and expressions with that function remain valid and can be calculated. To compose a new expression manually, type a function name.

If you have registered a custom function, you can call the CustomFunctions.Unregister method at application startup to unregister it..