Class TableObject
Represents a table object that consists of several rows and columns.
Inheritance
Inherited Members
Namespace: FastReport.Table
Assembly: FastReport.Base.dll
Syntax
public class TableObject : TableBase, IFRSerializable, IParent
Remarks
To add/remove columns, use the Columns collection. To add/remove rows, use the Rows collection. To initialize a table with specified number of columns and rows, use ColumnCount and RowCount properties.
To print a table in code, use the ManualBuild event. In the manual build mode, you can use aggregate functions. The following functions available:
Aggregate function | Description |
---|---|
Sum(cell) | Calculates the sum of values in specified table cell. |
Min(cell) | Calculates the minimum of values in specified table cell. |
Max(cell) | Calculates the maximum of values in specified table cell. |
Avg(cell) | Calculates the average of values in specified table cell. |
Count(cell) | Calculates the number of repeats of a specified table cell. |
To print aggregate value, place the aggregate function call in the table cell:
[Count(Cell2)]
.
Constructors
TableObject()
Initializes a new instance of the TableObject class.
Declaration
public TableObject()
Properties
ColumnCount
Declaration
public override int ColumnCount { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Overrides
ManualBuildAutoSpans
Determines whether to manage cell spans automatically during manual build.
Declaration
public bool ManualBuildAutoSpans { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
The default value for this property is true. If you set it to false, you need to manage spans in your ManualBuild event handler.
ManualBuildEvent
Gets or sets a script method name that will be used to handle the ManualBuild event.
Declaration
public string ManualBuildEvent { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
If you use this event, you must handle the table print process manually. See the ManualBuild event for details.
RowCount
Declaration
public override int RowCount { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Overrides
Methods
Assign(Base)
Declaration
public override void Assign(Base source)
Parameters
Type | Name | Description |
---|---|---|
Base | source |
Overrides
GetCustomScript()
Declaration
public override string GetCustomScript()
Returns
Type | Description |
---|---|
System.String |
Overrides
GetData()
Declaration
public override void GetData()
Overrides
OnAfterData(EventArgs)
Declaration
public override void OnAfterData(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.EventArgs | e |
Overrides
OnManualBuild(EventArgs)
This method fires the ManualBuild event and the script code connected to the ManualBuildEvent.
Declaration
public void OnManualBuild(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.EventArgs | e | Event data. |
PageBreak()
Adds a page before rows or columns.
Declaration
public void PageBreak()
Remarks
Call this method to insert a page break before the next row or column that you intend to print using PrintRow(s) or PrintColumn(s) methods. See the ManualBuild event for more details.
PrintColumn(Int32)
Prints a column with specified index.
Declaration
public void PrintColumn(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Index of a column to print. |
Remarks
See the ManualBuild event for more details.
PrintColumns()
Prints all columns.
Declaration
public void PrintColumns()
Remarks
See the ManualBuild event for more details.
PrintColumns(Int32[])
Prints columns with specified indices.
Declaration
public void PrintColumns(int[] indices)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | indices | Indices of columns to print. |
Remarks
See the ManualBuild event for more details.
PrintRow(Int32)
Prints a row with specified index.
Declaration
public void PrintRow(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Index of a row to print. |
Remarks
See the ManualBuild event for more details.
PrintRows()
Prints all rows.
Declaration
public void PrintRows()
Remarks
See the ManualBuild event for more details.
PrintRows(Int32[])
Prints rows with specified indices.
Declaration
public void PrintRows(int[] indices)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | indices | Indices of rows to print. |
Remarks
See the ManualBuild event for more details.
RestoreState()
Declaration
public override void RestoreState()
Overrides
SaveState()
Declaration
public override void SaveState()
Overrides
Serialize(FRWriter)
Declaration
public override void Serialize(FRWriter writer)
Parameters
Type | Name | Description |
---|---|---|
FRWriter | writer |
Overrides
Events
ManualBuild
Allows to print table rows/columns dynamically.
Declaration
public event EventHandler ManualBuild
Event Type
Type | Description |
---|---|
System.EventHandler |
Remarks
This event is used to handle the table print process in a code. Using special methods like PrintRow(Int32), PrintColumn(Int32) you can print specified rows/columns.
First way is to repeat specified row(s) to get a table that will grow downwards. To do this, you have to call the PrintRow method followed by the PrintColumns method.
Another way is to repeat the specified column(s) to get a table that grows sidewards. To do this, call the PrintColumn method followed by the PrintRows method.
Finally, the third way is to repeat rows and columns. The table will grow downwards and sidewards. To do this, call the PrintRow method followed by the PrintColumn method (or vice versa).
caution
When you print a table row-by-row, you must call one of the PrintColumn, PrintColumns methods right after the PrintRow method. In the same manner, when you print a table column-by-column, call one of the PrintRow, PrintRows methods right after the PrintColumn method. If you ignore this rule you will get an exception.
Examples
In this example, we will consider all three ways to print a table which has 3 rows and 3 columns.
Case 1: print a table downwards.
// print table header (the first row)
Table1.PrintRow(0);
Table1.PrintColumns();
// print table body (the second row)
for (int i = 0; i < 10; i++)
{
Table1.PrintRow(1);
Table1.PrintColumns();
}
// print table footer (the third row)
Table1.PrintRow(2);
Table1.PrintColumns();
Case 2: print a table sidewards.
// print table header (the first column)
Table1.PrintColumn(0);
Table1.PrintRows();
// print table body (the second column)
for (int i = 0; i < 10; i++)
{
Table1.PrintColumn(1);
Table1.PrintRows();
}
// print table footer (the third column)
Table1.PrintColumn(2);
Table1.PrintRows();
Case 3: print a table downwards and sidewards.
// print the first row with all its columns
Table1.PrintRow(0);
// print header column
Table1.PrintColumn(0);
// print 10 data columns
for (int i = 0; i < 10; i++)
{
Table1.PrintColumn(1);
}
// print footer column
Table1.PrintColumn(2);
// print table body (the second row)
for (int i = 0; i < 10; i++)
{
// print data row with all its columns
Table1.PrintRow(1);
Table1.PrintColumn(0);
for (int j = 0; j < 10; j++)
{
Table1.PrintColumn(1);
}
Table1.PrintColumn(2);
}
// print table footer (the third row)
Table1.PrintRow(2);
// again print all columns in the table footer
Table1.PrintColumn(0);
for (int i = 0; i < 10; i++)
{
Table1.PrintColumn(1);
}
Table1.PrintColumn(2);