Skip to main content
A newer version of this page is available. .

BandCollection Class

A collection of Band objects.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v21.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

public class BandCollection :
    XRControlCollection,
    IEnumerable<Band>,
    IEnumerable

Remarks

Use the BandCollection.Add and BandCollection.Remove methods to add or remove individual bands from the collection. You can also determine if a band is a member of the collection by passing the band to the BandCollection.Contains method. To get the index value of the band in the collection, pass this band to the BandCollection.IndexOf method.

Example

The following example demonstrates how to use the BandCollection class methods to construct a simple report. The AddMarginBands method creates two margin bands and adds them to the collection.

Note

The complete sample project is available in the following DevExpress Examples repository on GitHub: How to programmatically manage report bands.

using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...

public class XtraReport1 : DevExpress.XtraReports.UI.XtraReport {
// ...

    // ...
    // Generated code for the XtraReport1 class.
    // ...

    public void AddMarginBands() {

        // Check if the TopMargin band is already present in the report.
        if(Bands[BandKind.TopMargin] == null) {
            // Create a new TopMargin band and add it to the report.
            TopMarginBand tmBand = new TopMarginBand();
            Bands.Add(tmBand);

            // Create a label and set its text and width.
            XRLabel label = new XRLabel();
            label.Text = "TopMargin Band";
            label.Width = 200;

            // Add the label to the TopMargin band.
            tmBand.Controls.Add(label);
        }

        // Check if the BottomMargin band is already present in the report.
        if(Bands[BandKind.BottomMargin] == null) {
            // Create a new BottomMargin band and add it to the report.
            BottomMarginBand bmBand = new BottomMarginBand();
            Bands.Add(bmBand);

            // Create an XRPageInfo object and set its width and PageInfo option.
            XRPageInfo datePageInfo = new XRPageInfo();
            datePageInfo.Width = 200;
            datePageInfo.PageInfo = PageInfo.DateTime;

            // Add the page information control to the BottomMargin band.
            bmBand.Controls.Add(datePageInfo);
        }
    }

}

The following code handles button clicks to call the AddMarginBands method and show the preview:

XtraReport1 report = new XtraReport1();

private void btnPreview_Click(object sender, System.EventArgs e) {
    ReportPrintTool preview = new ReportPrintTool(report);
    preview.ShowPreview();
}

private void btnAddBands_Click(object sender, System.EventArgs e) {
    report.AddMarginBands();
}
See Also