DetailReportBand Class
A report band containing a nested detail report.
Namespace: DevExpress.XtraReports.UI
Assembly: DevExpress.XtraReports.v24.2.dll
NuGet Package: DevExpress.Reporting.Core
Declaration
Remarks
The DetailReportBand object is used to insert a detail report when creating hierarchical master-detail reports.
Use the XtraReportBase.DataSource and XtraReportBase.DataMember properties of a DetailReportBand to specify its data source.
Use the XtraReportBase.Bands property of a DetailReportBand to access its collection of bands.
See the following topics for more details:
Example
The code creates new Report Header and Detail bands at the detail level, and adds a table control to each band.
Table cells in the Detail band are bound to the data fields of the report data source. The table uses different styles for odd and even rows.
The width of both tables is set to the effective page width.
using DevExpress.DataAccess.Sql;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
using System.Drawing;
// ...
private static void CreateDetailReport(XtraReport report, string dataMember)
{
// Create a detail report band and bind it to data.
DetailReportBand detailReportBand = new DetailReportBand();
report.Bands.Add(detailReportBand);
detailReportBand.DataSource = report.DataSource;
detailReportBand.DataMember = dataMember;
// Add a header to the detail report.
ReportHeaderBand detailReportHeader = new ReportHeaderBand();
detailReportBand.Bands.Add(detailReportHeader);
XRTable tableHeader = new XRTable();
tableHeader.BeginInit();
tableHeader.Rows.Add(new XRTableRow());
tableHeader.Borders = BorderSide.All;
tableHeader.BorderColor = Color.DarkGray;
tableHeader.Font = new Font("Tahoma", 10, FontStyle.Bold);
tableHeader.Padding = 10;
tableHeader.TextAlignment = TextAlignment.MiddleLeft;
XRTableCell cellHeader1 = new XRTableCell();
cellHeader1.Text = "Product Name";
XRTableCell cellHeader2 = new XRTableCell();
cellHeader2.Text = "Unit Price";
cellHeader2.TextAlignment = TextAlignment.MiddleRight;
tableHeader.Rows[0].Cells.AddRange(new XRTableCell[] { cellHeader1, cellHeader2 });
detailReportHeader.Height = tableHeader.Height;
detailReportHeader.Controls.Add(tableHeader);
// Adjust the table width.
tableHeader.BeforePrint += tableHeader_BeforePrint;
tableHeader.EndInit();
// Create a detail band.
XRTable tableDetail = new XRTable();
tableDetail.BeginInit();
tableDetail.Rows.Add(new XRTableRow());
tableDetail.Borders = BorderSide.Left | BorderSide.Right | BorderSide.Bottom;
tableDetail.BorderColor = Color.DarkGray;
tableDetail.Font = new Font("Tahoma", 10);
tableDetail.Padding = 10;
tableDetail.TextAlignment = TextAlignment.MiddleLeft;
XRTableCell cellDetail1 = new XRTableCell();
XRTableCell cellDetail2 = new XRTableCell();
cellDetail2.TextAlignment = TextAlignment.MiddleRight;
cellDetail1.ExpressionBindings.Add(
new ExpressionBinding("BeforePrint", "Text", "[ProductName]"));
cellDetail2.ExpressionBindings.Add(
new ExpressionBinding("BeforePrint", "Text",
"FormatString('{0:$0.00}', [UnitPrice])"));
tableDetail.Rows[0].Cells.AddRange(new XRTableCell[] { cellDetail1, cellDetail2 });
DetailBand detailBand = new DetailBand();
detailBand.Height = tableDetail.Height;
detailReportBand.Bands.Add(detailBand);
detailBand.Controls.Add(tableDetail);
// Adjust the table width.
tableDetail.BeforePrint += tableDetail_BeforePrint;
tableDetail.EndInit();
// Create and assign different odd and even styles.
XRControlStyle oddStyle = new XRControlStyle();
XRControlStyle evenStyle = new XRControlStyle();
oddStyle.BackColor = Color.WhiteSmoke;
oddStyle.StyleUsing.UseBackColor = true;
oddStyle.Name = "OddStyle";
evenStyle.BackColor = Color.White;
evenStyle.StyleUsing.UseBackColor = true;
evenStyle.Name = "EvenStyle";
report.StyleSheet.AddRange(new XRControlStyle[] { oddStyle, evenStyle });
tableDetail.OddStyleName = "OddStyle";
tableDetail.EvenStyleName = "EvenStyle";
}
private static void AdjustTableWidth(XRTable table)
{
XtraReport report = table.RootReport;
table.WidthF = report.PageWidth - report.Margins.Left - report.Margins.Right;
}
static void tableHeader_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e)
{
AdjustTableWidth(sender as XRTable);
}
static void tableDetail_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e)
{
AdjustTableWidth(sender as XRTable);
}