Skip to main content

Implement a Custom Parameter Editor in WinForms Applications

  • 2 minutes to read

You can use BaseEdit class descendants as custom parameter editors in the Parameters panel. To change a parameter’s default editor to a custom editor, handle a report’s ParametersRequestBeforeShow event. Use the event’s ParametersInformation collection to access parameters. Assign a custom editor to the ParameterInfo.Editor property.

If you want to change the size of a custom parameter editor, use the editor’s MinimumSize/MaximumSize properties.

Example

The code sample below replaces a parameter’s default editor with a radio group.

Custom parameter editor

View Example: Reporting for WinForms - Implement a Custom Parameter Editor

[!codesnippet-csharp[dx-examples](reporting-winforms-implement-custom-parameter-editor/CS/XtraReport1.cs?line=1-3,11-41&alignIndents=true]

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraReports.Parameters;
// ...
private void XtraReport1_ParametersRequestBeforeShow(object sender, ParametersRequestEventArgs e) {
    // Create and set up a radio group editor.
    var radioGroup = CreateRadioGroup();

    // Find a required parameter by name and assign
    // a custom editor to the Editor property.
    foreach (var info in e.ParametersInformation) {
        if (info.Parameter.Name == "shape") {
            info.Editor = radioGroup;
            break;
        }
    }
}

private RadioGroup CreateRadioGroup() {
    var radioGroup = new RadioGroup();

    string[] radioGroupItemTitles = new string[] {
        "Circle", "Rectangle", "Ellipse",
        "Triangle", "Square"
    };

    foreach (var item in radioGroupItemTitles) {
        radioGroup.Properties.Items.Add(new RadioGroupItem(item, item));
    }

    radioGroup.Properties.ItemVertAlignment = RadioItemVertAlignment.Top;
    radioGroup.MinimumSize = new System.Drawing.Size(0, 100);

    return radioGroup;
}
See Also