Back to Devexpress

XRControlCollection.Add(XRControl) Method

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xrcontrolcollection-dot-add-x28-devexpress-dot-xtrareports-dot-ui-dot-xrcontrol-x29.md

latest8.0 KB
Original Source

XRControlCollection.Add(XRControl) Method

Adds the specified control to the collection.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public int Add(
    XRControl child
)
vb
Public Function Add(
    child As XRControl
) As Integer

Parameters

NameTypeDescription
childXRControl

An XRControl object to add to the collection.

|

Returns

TypeDescription
Int32

An integer value indicating the position into which the new element was inserted. If the control is already included in the collection the return value indicates the existing position of the control inside the collection.

|

Remarks

This method adds the control to the end of the collection.

Example

The following example shows two methods that use the XRControlCollection.Add, XRControlCollection.Remove and XRControlCollection.Contains methods of the XRControlCollection class. The first method adds a control to the control collection of the XRPanel object at the specified location. The second method checks if the specified control belongs to the specified collection, and if it does, it removes the control from the collection.

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

public void AddControl(XRPanel panel, XRControl item, int x, int y) {
    // Add a control to the collection.
    panel.Controls.Add(item);

    // Set the control's location within the panel.
    item.Location = new Point(x, y);
}

public void RemoveControl(XRPanel panel, XRControl item) {
    // Check if the control belongs to the collection.
    if(panel.Controls.Contains(item))

        // Remove the control from the collection.
        panel.Controls.Remove(item);
}
vb
Imports System.Drawing
Imports DevExpress.XtraReports.UI
' ...

Public Sub AddControl(ByRef panel As XRPanel, ByRef item As XRControl, _
ByVal x As Integer, ByVal y As Integer)
    ' Add a control to the collection.
    panel.Controls.Add(item)

    ' Set the control's location within the panel.
    item.Location = New Point(x, y)
End Sub

Public Sub RemoveControl(ByRef panel As XRPanel, ByRef item As XRControl)
    ' Check if the control belongs to the collection.
    If (panel.Controls.Contains(item)) Then

         ' Remove the control from the collection.
         panel.Controls.Remove(item)
    End If
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the Add(XRControl) method.

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-insert-a-shape-control/CS/Form1.cs#L37

csharp
// Preview the report.
report.Detail.Controls.Add(shape);
report.ShowPreview();

web-forms-dashboard-add-custom-information-to-exported-dashboard/CS/WebDashboard_CustomExport/Default.aspx.cs#L45

csharp
icon.WidthF = 300;
headerBand.Controls.Add(icon);

winforms-dashboard-add-custom-information-to-the-exported-dashboard/CS/WinViewer_CustomExport/Form1.cs#L16

csharp
var icon = new XRPictureBox();
topMarginBand.Controls.Add(icon);
icon.Image = Properties.Resources.dxLogo;

asp-net-web-forms-grid-create-report-based-on-grid-layout/CS/WebApplication1/Default.aspx.cs#L33

csharp
control.LocationF = new System.Drawing.PointF(0, 0);
e.Owner.Controls.Add(control);
control.Shape = new ShapeStar() { StarPointCount = 5, Concavity = 30 };

asp-net-mvc-grid-create-report-based-on-grid-layout/CS/E4755/Controllers/HomeController.cs#L47

csharp
control.LocationF = new System.Drawing.PointF(0, 0);
e.Owner.Controls.Add(control);
control.Shape = new ShapeStar() {

reporting-winforms-insert-a-shape-control/VB/Form1.vb#L35

vb
' Preview the report.
report.Detail.Controls.Add(shape)
report.ShowPreview()

asp-net-mvc-grid-create-report-based-on-grid-layout/VB/E4755/Controllers/HomeController.vb#L49

vb
control.LocationF = New System.Drawing.PointF(0, 0)
e.Owner.Controls.Add(control)
control.Shape = New ShapeStar() With {.StarPointCount = 5, .Concavity = 30}

web-forms-dashboard-add-custom-information-to-exported-dashboard/VB/WebDashboard_CustomExport/Default.aspx.vb#L44

vb
icon.WidthF = 300
headerBand.Controls.Add(icon)

winforms-dashboard-add-custom-information-to-the-exported-dashboard/VB/WinViewer_CustomExport/Form1.vb#L15

vb
Dim picture = New XRPictureBox()
topMarginBand.Controls.Add(picture)
picture.Image = My.Resources.dxLogo

asp-net-web-forms-grid-create-report-based-on-grid-layout/VB/WebApplication1/Default.aspx.vb#L35

vb
control.LocationF = New System.Drawing.PointF(0, 0)
e.Owner.Controls.Add(control)
control.Shape = New ShapeStar() With {

See Also

XRControlCollection Class

XRControlCollection Members

DevExpress.XtraReports.UI Namespace