Back to Devexpress

XRControl.Controls Property

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xrcontrol-717d8034.md

latest5.7 KB
Original Source

XRControl.Controls Property

Gets the collection of XRControl objects or their descendants that are contained in this control.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
[Browsable(false)]
public virtual XRControlCollection Controls { get; }
vb
<Browsable(False)>
Public Overridable ReadOnly Property Controls As XRControlCollection

Property Value

TypeDescription
XRControlCollection

An object of the XRControlCollection class representing the collection of contained controls.

|

Remarks

An XRControl object acts as a parent for any control contained within its collection. This collection is returned by its Controls property. Objects in this collection are considered to be child controls of the XRControl object. If a control can have child controls then its XRControl.CanHaveChildren property is equal to true.

Example

The following method aligns controls contained in an XRControl object. The controls are aligned with the topmost control. Access to the controls is provided via the XRControl.Controls property.

csharp
using System.Drawing;
using DevExpress.XtraReports.UI;
// ...

public void AlignHorizontally(XRControl container) {

    // Make sure that the collection is not empty.
    if(container.Controls.Count > 0) {

        // Assign the Y-coordinate of the first control in the collection to a variable.
        int y = container.Controls[0].Top;

        // Find the Y-coordinate of the topmost control.
        foreach(XRControl control in container.Controls) 
            if(control.Top < y)
                y = control.Top;

        // Align the controls with the topmost control.
        foreach(XRControl control in container.Controls) 
            control.Location = new Point(control.Left, y);
    }
}
vb
Imports System.Drawing
Imports DevExpress.XtraReports.UI
' ...

Public Sub AlignHorizontally(ByRef container As XRControl)

    ' Make sure that the collection is not empty.
    If container.Controls.Count > 0 Then

        ' Assign the Y-coordinate of the first control in the collection to a variable.
        Dim y As Integer = container.Controls(0).Top

        Dim control As XRControl
        ' Find the Y-coordinate of the topmost control.
        For Each control In container.Controls
            If (control.Top < y) Then
                y = control.Top
            End If
        Next

        ' Align the controls with the topmost control.
        For Each control In container.Controls
            control.Location = New Point(control.Left, y)
        Next
    End If
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the Controls property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

reporting-winforms-create-hierarchical-report-from-flat-table/CS/TreeViewReport/ChildReport.cs#L30

csharp
foreach(Band band in report.Bands)
    foreach(XRControl control in band.Controls) {
        if(control is XRTable)

reporting-winforms-use-subreport-to-add-a-chart/CS/Reporting-Use-Subreport-To-Add-A-Chart/Form1.cs#L153

csharp
};
var chart = report.Bands[0].Controls[0] as XRChart;
chart.Parameters.Add(new XRControlParameter("chartCategory", report.Parameters[0]));

reporting-winforms-create-hierarchical-report-from-flat-table/VB/TreeViewReport/ChildReport.vb#L31

vb
For Each band As Band In report.Bands
    For Each control As XRControl In band.Controls
        If TypeOf control Is XRTable Then TryCast(control, XRTable).WidthF = subreport.SizeF.Width

See Also

CanHaveChildren

Report Class Hierarchy

XRControl Class

XRControl Members

DevExpress.XtraReports.UI Namespace