xtrareports-devexpress-dot-xtrareports-dot-ui-2b22a0ba.md
A row in an XRTable.
Namespace : DevExpress.XtraReports.UI
Assembly : DevExpress.XtraReports.v25.2.dll
NuGet Package : DevExpress.Reporting.Core
public class XRTableRow :
XRControl,
IWeighty,
IWeightyContainer
Public Class XRTableRow
Inherits XRControl
Implements IWeighty,
IWeightyContainer
The following members return XRTableRow objects:
An XRTableRow object contains a collection of table cells. To access these cells, use the row’s Cells property. To add new cells to the row, use the Add method of this property. Utilize the row’s Table property to access the parent table of the current row.
The code sample below illustrates how to create a XRTable at runtime.
using DevExpress.XtraReports.UI;
// ...
// Create a report.
XtraReport report = new XtraReport();
// Create a detail band and add it to the report.
DetailBand detailBand = new DetailBand();
report.Bands.Add(detailBand);
// Create a table.
XRTable table = new XRTable();
// Add rows and columns to the table.
int numRows = 10;
int numCols = 20;
table.BeginInit();
for (int i = 0; i < numRows; i++) {
XRTableRow row = new XRTableRow();
table.Rows.Add(row);
for (int j = 0; j < numCols; j++) {
XRTableCell cell = new XRTableCell();
table.Rows[i].Cells.Add(cell);
}
}
// Set table size.
table.HeightF = 50;
table.WidthF = 500;
table.EndInit();
// Add the table to the detail band and adjust the band height.
detailBand.Controls.Add(table);
detailBand.HeightF = table.HeightF;
Imports DevExpress.XtraReports.UI
' ...
' Create a report.
Dim report As New XtraReport()
' Create a detail band and add it to the report.
Dim detailBand As New DetailBand()
report.Bands.Add(detailBand)
' Create a table.
Dim table As New XRTable()
' Add rows and columns to the table.
Dim numRows As Integer = 10
Dim numCols As Integer = 20
table.BeginInit()
For i As Integer = 0 To numRows - 1
Dim row As New XRTableRow()
table.Rows.Add(row)
For j As Integer = 0 To numCols - 1
Dim cell As New XRTableCell()
table.Rows(i).Cells.Add(cell)
Next j
Next i
' Set table size.
table.HeightF = 50
table.WidthF = 500
table.EndInit()
' Add the table to the detail band and adjust the band height.
detailBand.Controls.Add(table)
detailBand.HeightF = table.HeightF
Implement descendants of the XRTable and XRTableRow classes to create a custom table (for instance, a table with a different default row height or with pre-populated cells). Override the protected virtual XRTable.CreateRow and XRTableRow.CreateCell methods. These methods are invoked in all designer operations, except for multiple item drops from the Field List.
The code sample below illustrates custom table implementation.
using DevExpress.XtraReports.UI;
using System.ComponentModel;
// ...
namespace WindowsFormsApplication1 {
[ToolboxItem(true)]
public class XRTableEx : XRTable {
// Override the CreateRow() method to create a custom table row.
protected override XRTableRow CreateRow() {
return new XRTableRowEx();
}
}
// Implement a custom table row with specified height.
public class XRTableRowEx : XRTableRow {
public XRTableRowEx()
: base() {
SizeF = new System.Drawing.SizeF(120, this.DefaultHeight);
}
// Override the CreateCell() method to create a custom table cell.
protected override XRTableCell CreateCell() {
return new XRTableCellEx();
}
// Specify the default row height.
protected override int DefaultHeight {
get {
return 35;
}
}
}
// Implement a custom table cell with custom text.
public class XRTableCellEx : XRTableCell {
public XRTableCellEx() {
Text = "MyCustomXRTableCellEx";
}
}
}
Imports DevExpress.XtraReports.UI
Imports System.ComponentModel
' ...
Namespace WindowsFormsApplication1
<ToolboxItem(True)>
Public Class XRTableEx
Inherits XRTable
' Override the CreateRow() method to create a custom table row.
Protected Overrides Function CreateRow() As XRTableRow
Return New XRTableRowEx()
End Function
End Class
' Implement a custom table row with specified height.
Public Class XRTableRowEx
Inherits XRTableRow
Public Sub New()
MyBase.New()
SizeF = New System.Drawing.SizeF(120, Me.DefaultHeight)
End Sub
' Override the CreateCell() method to create a custom table cell.
Protected Overrides Function CreateCell() As XRTableCell
Return New XRTableCellEx()
End Function
' Specify the default row height.
Protected Overrides ReadOnly Property DefaultHeight() As Integer
Get
Return 35
End Get
End Property
End Class
' Implement a custom table cell with custom text.
Public Class XRTableCellEx
Inherits XRTableCell
Public Sub New()
Text = "MyCustomXRTableCellEx"
End Sub
End Class
End Namespace
Object MarshalByRefObject Component XRControl XRTableRow
See Also