Skip to main content

Hide Properties from the End-User Report Designer

  • 3 minutes to read

Handle the static XtraReport.FilterComponentProperties event to remove items from the Properties tab. Note that you should specify the property name. Avoid any confusion between the name of a property and its display name. The following image shows the BackColor property (property name) displayed as “Background Color” (display name):

Background Color Property Display Name

The following code snippet hides properties in the End-User Report Designer‘s Properties panel:

using System;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.UserDesigner;
using System.ComponentModel;

namespace WindowsFormsApplication1 {
static class Program {
    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        // Handle the static FilterComponentProperties event to filter the Property Grid. 
        XtraReport.FilterComponentProperties += XtraReport_FilterComponentProperties;

        Application.Run(new Form1());
    }

    static void XtraReport_FilterComponentProperties(object sender, 
        FilterComponentPropertiesEventArgs e) {

        // Hide the Background Color property for all report elements.
        HideProperty("BackColor", e);

        // Hide the ReportSource and ReportSourceUrl properties for subreports.
        if (e.Component is XRSubreport) {
            HideProperty("ReportSource", e);     
            HideProperty("ReportSourceUrl", e);    
        }  

        // Hide the Name property for a specific label control.
        if (sender is XtraReport1 && e.Component is XRControl && 
            ((XRControl)e.Component).Name == "label1") {
            HideProperty("Name", e);
        }
    }

    static void HideProperty(String propertyName, 
        FilterComponentPropertiesEventArgs filterComponentProperties) {
        PropertyDescriptor oldPropertyDescriptor = 
            filterComponentProperties.Properties[propertyName] as PropertyDescriptor;
        if (oldPropertyDescriptor != null) {
                // Substitute the current property descriptor 
                // with a custom descriptor with the BrowsableAttribute.No attribute.
                filterComponentProperties.Properties[propertyName] = TypeDescriptor.CreateProperty(
                oldPropertyDescriptor.ComponentType,
                oldPropertyDescriptor,
                new Attribute[] { BrowsableAttribute.No });
        }
            else {
            // If the property descriptor cannot be substituted, 
            // remove it from the Properties collection.
            filterComponentProperties.Properties.Remove(propertyName);
            }
        }
    }
}