Skip to main content

Make a Custom Control Available Only for a Specific Report

  • 2 minutes to read

This example adds a custom control to the toolbox in the End-User Report Designer for Winforms. The XtraReport.DesignerLoaded event is used to access the toolbox service.

Tip

This code adds the XRZipCode control to the toolbox. It is hidden by default because most countries do not use it.

See Use Custom Controls to learn how to create custom report controls and add them to a Report Designer’s toolbox.

using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.UserDesigner;
using System.Drawing.Design;
// ...

private void button1_Click(object sender, System.EventArgs e) {
    XtraReport1 report = new XtraReport1();
    ReportDesignTool designTool = new ReportDesignTool(report);
    report.DesignerLoaded += report_DesignerLoaded;
    designTool.ShowRibbonDesignerDialog();
}

void report_DesignerLoaded(object sender, DesignerLoadedEventArgs e) {
    // Access the Toolbox service.
    IToolboxService toolboxService = 
        (IToolboxService)e.DesignerHost.GetService(typeof(IToolboxService));

    // Add a custom control to the default category.
    toolboxService.AddToolboxItem(new ToolboxItem(typeof(XRZipCode)));

    // Add a custom control to a new category.
    // toolboxService.AddToolboxItem(new ToolboxItem(typeof(XRZipCode)), "New Category");
}

Tip

The added report control becomes available only for the specified report instance.

See Add a Custom Control to the Report Designer Toolbox to learn how to make added controls available in any report.

See Also