Class TableObject
Represents a table object that consists of several rows and columns.
Inheritance
Inherited Members
Namespace: FastReport.Table
Assembly: FastReport.OpenSource.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
Gets or sets a number of columns in the table.
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
Gets or sets a number of rows in the table.
Declaration
public override int RowCount { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Overrides
Methods
Assign(Base)
Copies the contents of another, similar object.
Declaration
public override void Assign(Base source)
Parameters
Type | Name | Description |
---|---|---|
Base | source | Source object to copy the contents from. |
Overrides
Remarks
Call Assign to copy the properties from another object of the same type. The standard form of a call to Assign is
destination.Assign(source);
which tells the destination object to copy the contents of the source object to itself. In this method, all child objects are ignored. If you want to copy child objects, use the AssignAll(Base) method.
See Also
GetCustomScript()
Returns a custom code that will be added to the report script before report is run.
Declaration
public override string GetCustomScript()
Returns
Type | Description |
---|---|
System.String | A custom script text, if any. Otherwise returns null. |
Overrides
Remarks
This method may return any valid code that may be inserted into the report script. Currently it is used in the TableObject to define the following script methods: Sum, Min, Max, Avg, Count.
Note: you must take into account the current script language - C# or VB.Net. You may check it via Report.ScriptLanguage property.
GetData()
Gets the data from a datasource that the object is connected to.
Declaration
public override void GetData()
Overrides
Remarks
This method is called by the report engine before processing the object.
Do not call it directly. You may override it if you are developing a new FastReport component. In this method you should get the data from a datasource that the object is connected to.
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()
Restores the object's state after printing it.
Declaration
public override void RestoreState()
Overrides
Remarks
This method is called by the report engine after processing the object.
Do not call it directly. You may override it if you are developing a new FastReport component. In this method you should restore the object properties that were saved by the SaveState() method.
SaveState()
Saves the object's state before printing it.
Declaration
public override void SaveState()
Overrides
Remarks
This method is called by the report engine before processing the object.
Do not call it directly. You may override it if you are developing a new FastReport component. In this method you should save any object properties that may be changed during the object printing. The standard implementation saves the object's bounds, visibility, bookmark and hyperlink.
Serialize(FRWriter)
Serializes the object.
Declaration
public override void Serialize(FRWriter writer)
Parameters
Type | Name | Description |
---|---|---|
FRWriter | writer | Writer object. |
Overrides
Remarks
Do not call this method directly. You should override it if you are developing a new component for FastReport.
This method is called when the object needs to save the state. It may happen when:
- saving the report to the file or stream;
- saving the report to the designer's undo buffer;
- assigning the object to another object using the Assign(Base) or AssignAll(Base) methods;
- saving the object to the designer's clipboard;
- saving the object to the preview (when run a report).
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);