Back to Devexpress

FilterControlPropertiesEventArgs.Control Property

xtrareports-devexpress-dot-xtrareports-dot-userdesigner-dot-filtercontrolpropertieseventargs.md

latest7.5 KB
Original Source

FilterControlPropertiesEventArgs.Control Property

Provides access to a control, whose properties can be filtered in thisXtraReport.FilterControlProperties event’s handler.

Namespace : DevExpress.XtraReports.UserDesigner

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public XRControl Control { get; }
vb
Public ReadOnly Property Control As XRControl

Property Value

TypeDescription
XRControl

An XRControl class descendant, representing a report control, report band or a report itself, whose properties can be filtered.

|

Remarks

Use the Control property to determine a control or a band, for which it is necessary to hide some properties from end-users in the End-User Designer, and the FilterControlPropertiesEventArgs.Properties property to manage the list of visible properties.

Example

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 ):

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

csharp
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);
            }
        }
    }
}
vb
Imports System.ComponentModel
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.UserDesigner

Namespace WindowsFormsApplication1
    Friend NotInheritable Class Program
        Private Sub New()
        End Sub

        <STAThread>
        Shared Sub Main()
            Application.EnableVisualStyles()
            Application.SetCompatibleTextRenderingDefault(False)

            ' Handle the static FilterComponentProperties event to filter the Property Grid. 
            AddHandler XtraReport.FilterComponentProperties, AddressOf XtraReport_FilterComponentProperties

            Application.Run(New Form1())
        End Sub

        Private Shared Sub XtraReport_FilterComponentProperties(ByVal sender As Object, ByVal e As FilterComponentPropertiesEventArgs)

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

            ' Hide the ReportSource and ReportSourceUrl properties for subreports.
            If TypeOf e.Component Is XRSubreport Then
                HideProperty("ReportSource", e)
                HideProperty("ReportSourceUrl", e)
            End If

            ' Hide the Name property for a specific label control.
            If TypeOf sender Is XtraReport1 AndAlso TypeOf e.Component Is XRControl AndAlso CType(e.Component, XRControl).Name = "label1" Then
                HideProperty("Name", e)
            End If

        End Sub

        Private Shared Sub HideProperty(ByVal propertyName As String, ByVal filterComponentProperties As FilterComponentPropertiesEventArgs)
            Dim oldPropertyDescriptor As PropertyDescriptor = TryCast(filterComponentProperties.Properties(propertyName), PropertyDescriptor)
            If oldPropertyDescriptor IsNot Nothing Then
                ' 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)
            End If
        End Sub
    End Class
End Namespace

See Also

FilterControlPropertiesEventArgs Class

FilterControlPropertiesEventArgs Members

DevExpress.XtraReports.UserDesigner Namespace