xtrareports-devexpress-dot-xtrareports-dot-ui-820f9950.md
A report band containing a nested detail report.
Namespace : DevExpress.XtraReports.UI
Assembly : DevExpress.XtraReports.v25.2.dll
NuGet Package : DevExpress.Reporting.Core
public class DetailReportBand :
XtraReportBase,
IMoveableBand,
IDrillDownNode
Public Class DetailReportBand
Inherits XtraReportBase
Implements IMoveableBand,
IDrillDownNode
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:
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 DevExpress.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 DXFont("Tahoma", 10, DXFontStyle.Bold);
tableHeader.Padding = new PaddingInfo(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 DXFont("Tahoma", 10);
tableDetail.Padding = new PaddingInfo(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);
}
Imports DevExpress.DataAccess.Sql
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraReports.UI
Imports DevExpress.Drawing
' ...
Private Shared Sub CreateDetailReport(ByVal report As XtraReport, ByVal dataMember As String)
' Create a detail report band and bind it to data.
Dim detailReportBand As New DetailReportBand()
report.Bands.Add(detailReportBand)
detailReportBand.DataSource = report.DataSource
detailReportBand.DataMember = dataMember
' Add a header to the detail report.
Dim detailReportHeader As New ReportHeaderBand()
detailReportBand.Bands.Add(detailReportHeader)
Dim tableHeader As New XRTable()
tableHeader.BeginInit()
tableHeader.Rows.Add(New XRTableRow())
tableHeader.Borders = BorderSide.All
tableHeader.BorderColor = Color.DarkGray
tableHeader.Font = New DXFont("Tahoma", 10, DXFontStyle.Bold)
tableHeader.Padding = New PaddingInfo(10)
tableHeader.TextAlignment = TextAlignment.MiddleLeft
Dim cellHeader1 As New XRTableCell()
cellHeader1.Text = "Product Name"
Dim cellHeader2 As 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.
AddHandler tableHeader.BeforePrint, AddressOf tableHeader_BeforePrint
tableHeader.EndInit()
' Create a detail band.
Dim tableDetail As New XRTable()
tableDetail.BeginInit()
tableDetail.Rows.Add(New XRTableRow())
tableDetail.Borders = BorderSide.Left Or BorderSide.Right Or BorderSide.Bottom
tableDetail.BorderColor = Color.DarkGray
tableDetail.Font = New DXFont("Tahoma", 10)
tableDetail.Padding = New PaddingInfo(10)
tableDetail.TextAlignment = TextAlignment.MiddleLeft
Dim cellDetail1 As New XRTableCell()
Dim cellDetail2 As 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 })
Dim detailBand As New DetailBand()
detailBand.Height = tableDetail.Height
detailReportBand.Bands.Add(detailBand)
detailBand.Controls.Add(tableDetail)
' Adjust the table width.
AddHandler tableDetail.BeforePrint, AddressOf tableDetail_BeforePrint
tableDetail.EndInit()
' Create and assign different odd and even styles.
Dim oddStyle As New XRControlStyle()
Dim evenStyle As 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"
End Sub
Private Shared Sub AdjustTableWidth(ByVal table As XRTable)
Dim report As XtraReport = table.RootReport
table.WidthF = report.PageWidth - report.Margins.Left - report.Margins.Right
End Sub
Private Shared Sub tableHeader_BeforePrint(ByVal sender As Object,
ByVal e As System.ComponentModel.CancelEventArgs)
AdjustTableWidth(TryCast(sender, XRTable))
End Sub
Private Shared Sub tableDetail_BeforePrint(ByVal sender As Object,
ByVal e As System.ComponentModel.CancelEventArgs)
AdjustTableWidth(TryCast(sender, XRTable))
End Sub
Object MarshalByRefObject Component XRControl Band XtraReportBase DetailReportBand
See Also
Introduction to Banded Reports
Create a Master-Detail Report with a Detail Report Band in the VS Report Designer