Back to Devexpress

Prompt to Expression

windowsforms-405608-ai-powered-extensions-prompt-to-expression.md

latest7.7 KB
Original Source

Prompt to Expression

  • Oct 14, 2025
  • 4 minutes to read

Prompt to Expression converts natural language into valid filter and unbound column expressions for data-aware WinForms controls. Instead of writing complex expressions, users describe the desired logic in plain text:

Sample Filter Expression_Display orders expected to arrive within 7 days.Sample Unbound Column Expression_Compute total amount.

The system sends the prompt to the configured AI service, which generates a valid expression for the control. The Expression Editor or Filter Editor displays and validates the result immediately.

Run Demo: Prompt to Expression

Supported Controls

ControlEditorSupported
GridControlExpression Editor / Filter EditorYes
TreeListExpression Editor / Filter EditorYes
VGridControlExpression Editor / Filter EditorYes

Note

  • Prompt to Expression works at runtime only.
  • Legacy Expression and Filter Editors are not supported.

How It Works

Filter Editor

  1. The user opens the Filter Editor.

  2. The user enters an intent in the Prompt to Expression field and clicks Send.

  3. AI generates a filter expression. The Filter Editor displays the result.

Expression Editor

  1. The user opens the Expression Editor for an unbound column.

  2. The user enters an intent in the Prompt to Expression field and clicks Send.

  3. AI generates the expression. The Expression Editor displays the result.

Activate Prompt to Expression

Prerequisites

.NET 8 SDK / .NET Framework v4.7.2

Install DevExpress NuGet Packages

  1. DevExpress.AIIntegration.WinForms
  2. DevExpress.Win.Design (design-time infrastructure)

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

Register AI Client

See the following help topic for information on required NuGet packages and system requirements: Register an AI Client.

The following code snippet registers the Azure OpenAI client:

csharp
using Microsoft.Extensions.AI;
using DevExpress.AIIntegration;

internal static class Program {
    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        IChatClient azureChatClient = new Azure.AI.OpenAI.AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
            new System.ClientModel.ApiKeyCredential(AzureOpenAIKey))
            .GetChatClient(ModelId).AsIChatClient();
        AIExtensionsContainerDesktop.Default.RegisterChatClient(azureChatClient);
        // Uncomment the following line if your project targets the .NET Framework and
        // you create AI-powered behaviors in code.
        // DevExpress.AIIntegration.WinForms.BehaviorInitializer.Initialize();
        Application.Run(new Form1());
    }
    static string AzureOpenAIEndpoint { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"); } }
    static string AzureOpenAIKey { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY"); } }
    static string ModelId { get { return "MODEL_NAME"; } }
}
vb
Imports Microsoft.Extensions.AI
Imports DevExpress.AIIntegration

Friend Module Program
    <STAThread>
    Sub Main()
        Application.EnableVisualStyles()
        Application.SetCompatibleTextRenderingDefault(False)
        ' Register Azure.OpenAI
        Dim azureChatClient As IChatClient = New Azure.AI.OpenAI.AzureOpenAIClient(New Uri(AzureOpenAIEndpoint),
            New System.ClientModel.ApiKeyCredential(AzureOpenAIKey)).
            GetChatClient(ModelId).AsIChatClient()
        AIExtensionsContainerDesktop.Default.RegisterChatClient(azureChatClient)
        ' Uncomment the following line if your project targets the .NET Framework and
        ' you create AI-powered behaviors in code.
        ' DevExpress.AIIntegration.WinForms.BehaviorInitializer.Initialize()
        Application.Run(New Form1())
    End Sub
    Private ReadOnly Property AzureOpenAIEndpoint() As String
        Get
            Return Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
        End Get
    End Property
    Private ReadOnly Property AzureOpenAIKey() As String
        Get
            Return Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY")
        End Get
    End Property
    Private ReadOnly Property ModelId As String
        Get
            Return "MODEL_NAME"
        End Get
    End Property
End Module

Attach Prompt to Expression Behavior

  1. Drop the BehaviorManager component from the Toolbox onto a Form.
  2. Add a PromptToExpressionBehavior, configure its settings, and attach the behavior to a DevExpress UI control (GridControl, VGridControl, or TreeList). You can do this at design time or in code:

Behavior Properties

PropertyDescription
TargetSpecifies the attached control (GridControl, VGridControl, or TreeList).
RetryAttemptCountSpecifies the number of additional attempts the AI makes to regenerate an expression if the previous result is invalid.
TemperatureSpecifies creativity in AI responses. Set 1 for models (for example, GPT-5, o1, and o3 series) that ignore this parameter to avoid compatibility errors.
PromptAugmentationAppends additional instructions to each user prompt.
AugmentWithFunctionInfoInjects supported functions and operators into each user prompt. Increases accuracy. Adds about 4,000 tokens per request (adds cost). Default : true.

Specific Notes

Runtime ScopeDesign-time Filter and Expression Editors are not supported.Legacy EditorsLegacy Expression and Filter Editors do not integrate AI.Retry PolicyUse the RetryAttemptCount property to specify how many times the system retries expression generation.Error HandlingExpression and Filter Editors validate the generated expression and display an error message if all attempts produce invalid exceptions.