Reports for WinForms | ComponentOne
Working with C1PrintDocument / Tables
In This Topic
    Tables
    In This Topic

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

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim rt1 As New C1.C1Preview.RenderTable()
    

    To write code in C#

    C#
    Copy Code
    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:

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

    To write code in Visual Basic

    Visual Basic
    Copy Code
    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
    

    To write code in C#

    C#
    Copy Code
    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).

    See Also