ComponentOne Reports for WinForms Designer Edition: ComponentOne Reports for WinForms > Working with C1PrintDocument > Tables > Groups of Rows and Columns, Headers and Footers

Groups of Rows and Columns, Headers and Footers

Element groups are a very powerful feature of tables. Groups allow accessing several elements of a table as a whole (for example, the style can be set on a group as if it were a single element). Supported are groups of columns, groups of rows, and groups of cells.

To access a group of rows, use the collection RowGroups (which has the type TableVectorGroupCollection). Elements of that collection have the type TableVectorGroup, with some useful properties defined on that type. One of the more interesting of those properties is ColumnHeader. That property allows assigning a group of rows to be a table header, to be repeated at the top of each new page or page column. A related property is ColumnFooter, which allows to assign a group of rows to be a table footer, again repeated either at the end of each page or page column.

The following line of code shows how to assign the first 2 rows of a table to be the table header, repeated after each page or column break (rt1 here is a RenderTable object):

      Visual Basic

rt1.RowGroups(0, 2).Header = C1.C1Preview.TableHeaderEnum.Page

      C#

rt1.RowGroups[0, 2].Header = C1.C1Preview.TableHeaderEnum.Page;

As seen above, the indexer on the TableVectorGroupCollection class accepts two integers. The first value is the index of the first row included in the group (0 in the code example above). The second value is the count of rows in the group (2 in the code example above).

To access a group of columns, the collection ColGroups should be used. It has the same type as the row groups' collection (TableVectorGroupCollection), and provides the same functionality. Of particular interest is the ability to assign a group of columns to be a vertical table header or footer. C1PrintDocument supports "horizontal" (or "extension") pages, which allow wide objects to span several pages horizontally. To allow an object (for example, a table) to span several pages horizontally, set its SplitHorzBehavior to a value other than SplitBehaviorEnum.Never. If the object's width is wider than the page width, it will be split into several horizontal pages. In particular, a wide table can be split in this way. To make a group of columns repeat along the left edge of each page, set the group's ColumnHeader property to True. To make a group of columns repeat along the right edge of each page, set the group's ColumnFooter property to True.

Note: Although any group of rows (or columns) of a table can be assigned to be the footer, normally you would want to include only the last rows (or columns) of the table into the footer group. This will ensure that the footer behaves as a normal footer – that is appears only at the bottom (or right edge) of pages, and also appears at the end of the table. (If, for example, you assign the first row of a table to be the footer, it will still appear at the beginning of the table, and also will not print at the end of the table.)

Here is an example of code that creates a table with 100 rows and 10 columns, sets the width of the table to Auto, explicitly sets the width of each column to 1 inch, and also assigns horizontal and vertical table headers and footers:

      Visual Basic

' Create and fill the table.

Dim rt1 As C1.C1Preview.RenderTable = New C1.C1Preview.RenderTable()

Dim row As Integer = 0

Dim col As Integer

Do While (row < 100)

    col = 0

    Do While (col < 6)

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

        col += 1

    Loop

    row += 1

Loop

 

' Set the table and columns' widths.

rt1.Width = C1.C1Preview.Unit.Auto

col = 0

Do While (col < 6)

    rt1.Cols(col).Width = "1in"

    col += 1

Loop

 

' Assign the first 2 rows as the header and set the background.

rt1.RowGroups(0, 2).PageHeader = True

rt1.RowGroups(0, 2).Style.BackColor = Color.Red

 

' Assign the last 2 rows as the footer and set the background.

rt1.RowGroups(98, 2).PageFooter = True

rt1.RowGroups(98, 2).Style.BackColor = Color.Blue

 

' Assign the first column as the header.

rt1.ColGroups(0, 1).PageHeader = True

rt1.ColGroups(0, 1).Style.BackColor = Color.BlueViolet

 

' Assign the last column as the footer.

rt1.ColGroups(5, 1).PageFooter = True

rt1.ColGroups(5, 1).Style.BackColor = Color.BurlyWood

      C#

// Create and fill the table.

RenderTable rt1 = new RenderTable();

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

{

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

    {

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

    }

}

 

// Set the table and columns' widths.

rt1.Width = Unit.Auto;

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

{

    rt1.Cols[col].Width = "1in";

}

 

// Assign the first 2 rows as the header and set the background.

rt1.RowGroups[0, 2].PageHeader = true;

rt1.RowGroups[0, 2].Style.BackColor = Color.Red;

 

// Assign the last 2 rows as the footer and set the background.

rt1.RowGroups[98, 2].PageFooter = true;

rt1.RowGroups[98, 2]. Style.BackColor = Color.Blue;

 

// Assign the first column as the header.

rt1.ColGroups[0, 1].PageHeader = true;

rt1.ColGroups[0, 1].Style.BackColor = Color.BlueViolet;

 

// Assign the last column as the footer.

rt1.ColGroups[5, 1].PageFooter = true;

rt1.ColGroups[5, 1].Style.BackColor = Color.BurlyWood;

In this sample, background color is used to highlight row and column groups.


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