Back to Devexpress

Generate Expressions from Prompts (WinForms Report Designer)

xtrareports-405646-ai-powered-functionality-desktop-reporting-generate-expressions-from-prompts-win-forms-report-designer.md

latest7.2 KB
Original Source

Generate Expressions from Prompts (WinForms Report Designer)

  • Dec 11, 2025
  • 4 minutes to read

Prompt to Expression converts natural language into valid expressions. Instead of writing complex expressions, users describe the desired logic in plain text.

The system sends the prompt to the configured AI service, which generates a valid expression. The Expression Editor or Filter Editor displays the result immediately. If Prompt to Expression fails to create a valid expression, it displays a message that informs the user that a valid expression was not generated.

Run Demo: Prompt to Expression

How It Works

Expression Editor

  1. The user opens the Expression Editor , enters a prompt in the Prompt to Expression field, and clicks Send.

  2. AI generates the expression and the Expression Editor displays the result.

Filter Editor

  1. The user opens the Filter Editor , enters a prompt in the Prompt to Expression field, and clicks Send.

  2. AI generates a filter expression and the Filter Editor displays the result.

Activate Prompt to Expression

Prerequisites

  • .NET 8+ SDK / .NET Framework v4.7.2
  • Visual Studio 2022+

Install NuGet Packages

Install the following NuGet packages:

See the following help topics for information on how to obtain the DevExpress NuGet Feed and install DevExpress NuGet packages:

Note

DevExpress AI-powered extensions follow the “bring your own key” principle. DevExpress does not offer a REST API and does not ship any built-in LLMs/SLMs. You need an active Azure/Open AI subscription to obtain the REST API endpoint, key, and model deployment name. These variables must be specified at application startup to register AI clients and enable DevExpress AI-powered Extensions in your application.

Register AI Client

The following code snippet registers an Azure OpenAI client at application startup:

csharp
using Azure.AI.OpenAI;
using DevExpress.AIIntegration;
using Microsoft.Extensions.AI;
using System.ClientModel;

internal static class Program {
    static string AzureOpenAIEndpoint { get { return "AZURE_OPENAI_ENDPOINT"; } }
    static string AzureOpenAIKey { get { return "AZURE_OPENAI_APIKEY"; } }
    static string DeploymentName { get { return "MODEL_NAME"; } } // For example, gpt-4.1.
    [STAThread]
    static void Main(){
        IChatClient client = new AzureOpenAIClient(
            new Uri(AzureOpenAIEndpoint),
            new ApiKeyCredential(AzureOpenAIKey))
                .GetChatClient(DeploymentName).AsIChatClient(); 
        AIExtensionsContainerDesktop.Default.RegisterChatClient(client);
        ApplicationConfiguration.Initialize();
        Application.Run(new Form1());
    }
}
vb
Imports Azure.AI.OpenAI
Imports DevExpress.AIIntegration
Imports Microsoft.Extensions.AI
Imports System.ClientModel

Friend Module Program
    Private ReadOnly Property AzureOpenAIEndpoint() As String
        Get
            Return "AZURE_OPENAI_ENDPOINT"
        End Get
    End Property
    Private ReadOnly Property AzureOpenAIKey() As String
        Get
            Return "AZURE_OPENAI_APIKEY"
        End Get
    End Property
    Private ReadOnly Property DeploymentName() As String
        Get
            Return "MODEL_NAME"
        End Get
    End Property
        <STAThread>
        Sub Main()
        Dim client As IChatClient = (New AzureOpenAIClient(New Uri(AzureOpenAIEndpoint), New ApiKeyCredential(AzureOpenAIKey))).GetChatClient(DeploymentName).AsIChatClient()
        AIExtensionsContainerDesktop.Default.RegisterChatClient(client)
        ApplicationConfiguration.Initialize()
        Application.Run(New Form1())
        End Sub
End Module

Tip

How to Register OpenAI, Azure OpenAI, Ollama, and Semantic Kernel Clients.

Attach Prompt to Expression Behavior

  1. Drop the BehaviorManager component from the Toolbox onto a Form that contains the WinForms Report Designer.

  2. Invoke the BehaviorManager‘s smart tag menu and click Edit Behaviors to open the Behavior Collection Editor.

  3. Add a ReportPromptToExpressionBehavior and specify its settings.

Create and Configure Behavior Object in Code

Drop the BehaviorManager component from the Toolbox onto a Form that contains the WinForms Report Designer control. Use the following code to register a ReportPromptToExpressionBehavior and attach it to the Report Designer (reportDesigner1):

csharp
using DevExpress.AIIntegration.WinForms.Reporting;
using DevExpress.XtraEditors;

namespace ReportPromptToExpression {
    public partial class Form1 : XtraForm {
        public Form1() {
            InitializeComponent();

            // The behaviorManager1 component must be added to the Form at design time.
            behaviorManager1.Attach<ReportPromptToExpressionBehavior>(reportDesigner1, behavior => {
                behavior.Properties.MaxRetryAttempts = 5;
            });

            reportDesigner1.OpenReport(new Report1());
        }
    }
}

Note

Call the BehaviorInitializer.Initialize() method at application startup if your project targets the .NET Framework and you create AI-powered behaviors in code. Otherwise, an exception is thrown.

csharp
internal static class Program {
    [STAThread]
    static void Main() {
        //...
        // The Initialize() method forcibly initializes the behavior manager in .NET Framework apps.
        DevExpress.AIIntegration.WinForms.Reporting.BehaviorInitializer.Initialize();
        Application.Run(new Form1());
    }
}

Specific Details and Limitations

The following editors do not support Prompt to Expression :

  • Filter Editor in the SQL Data Source Query Builder
  • Column Expression Editor in the Federated Data Source Query Builder