Skip to main content
All docs
V23.2

Remove a Function from the Expression Editor

  • 2 minutes to read

You can remove a function from the Expression Editor. To do this, create a ReportExpressionEditorCustomizationService descendant, override the BeforeRun method, and delete the function from the ExpressionEditorContext.Functions collection.

The following code is a custom service that removes the “Abs” function from the list of available functions in the Expression Editor:

using DevExpress.Data.Controls.ExpressionEditor;
using DevExpress.XtraReports.UserDesigner;
using System.Linq;

namespace CustomFunctionForExpressionEditorExample
{
    class CustomReportExpressionEditorCustomizationService : ReportExpressionEditorCustomizationService
    {
        public CustomReportExpressionEditorCustomizationService() {}
        public override void BeforeRun(string expressionString, 
            IExpressionEditorView expressionEditorView, 
            ExpressionEditorContext expressionEditorContext)
        {
            FunctionInfo formatStringFunc = expressionEditorContext.Functions
                .FirstOrDefault(x => x.Name == "Abs");
            expressionEditorContext.Functions.Remove(formatStringFunc);
            base.BeforeRun(expressionString, expressionEditorView, expressionEditorContext);
        }
    }
}

You should register the service at application startup:

    {
        DevExpress.XtraReports.Expressions.CustomFunctions.Register(new NewLineConstant());
        // ...
            typeof(DevExpress.XtraReports.UserDesigner.ReportExpressionEditorCustomizationService),
            new CustomReportExpressionEditorCustomizationService());
        reportDesigner1.OpenReport(new Reports.XtraReport1());
        // ...
}

When you run the application, the Abs function is not shown in the list of available functions, but it remains valid and can be evaluated in expressions:

View Example: Expression Editor - How to Implement a Custom Function

See Also