ComponentOne Reports for WinForms Designer Edition: ComponentOne Reports for WinForms > Working with C1PrintDocument > Tables

Tables

Tables are represented by instances of the RenderTable class. To create a table, just invoke its constructor, for example like this:

      Visual Basic

Dim rt1 As New C1.C1Preview.RenderTable()

      C#

RenderTable rt1 = new RenderTable();

C1PrintDocument tables follow the model of Microsoft Excel. Though a newly created table is physically empty (that is, it does not take much space in memory), logically it is infinite: you can access any element (cell, row, or column) of a table without first adding rows or columns, and writing to that element will logically create all elements preceding it. For instance, setting the text of the cell of an empty table at row index 9 and column index 3 will make the table grow to 10 rows and 4 columns.

To add content to a table, you must fill the cells with data. This can be done in one of the following ways:

      By setting the cell's RenderObject property to an arbitrary render object. This will insert the specified render object into that cell. Any render object can be added to a cell, including another table, thus allowing nested tables.

      By setting the cell's Text property to a string. This is actually a handy shortcut to create text-only tables, which internally creates a new RenderText object, sets the cell's RenderObject property to that RenderText, and sets that object's Text property to the specified string.

So, for example, the following code snippet will create a table with 10 rows and 4 columns:

      Visual Basic

Dim rt1 As New C1.C1Preview.RenderTable()

Dim row As Integer = 0

Do While (row < 10)

    Dim col As Integer = 0

    Do While (col < 4)

        rt1.Cells(row, col).Text = String.Format( _
          "Text in cell({0}, {1})", row, col)

        col += 1

    Loop

    row += 1

Loop

      C#

RenderTable rt1 = new RenderTable();

for (int row = 0; row < 10; ++row)

{

    for (int col = 0; col < 4; ++col)

        rt1.Cells[row, col].Text = string.Format(
          "Text in cell({0}, {1})", row, col);

}

At any time, you can find out the actual current size of a table by querying the values of properties Cols.Count (which returns the current number of columns) and Rows.Count (which returns the current number of rows).


Accessing Cells, Columns and Rows

Table and Column Width, Row Height

Groups of Rows and Columns, Headers and Footers

User Cell Groups

Styles in Tables


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.