TableGrid Fundamentals

Overview

The TableGrid component is used to print a table in a report. A table consists of rows and columns that define a grid of cells. Cells may contain objects such as Label, DBText, Memo, Image etc. Simply drag-and-drop the object to the Cell. The Cell by default manages the child object’s boundary based on the Cell’s Padding and the child object’s Anchors.

Use the RowCount and ColCount properties to specify the number of rows and cols.

Use the Row.RowType property to specify header, detail, footer rows.

Cell ColSpan and RowSpan can be used to define cells that span multiple cols and/or rows.

Use the MasterGrid property to link grids, so that when the master grid changes position or column widths, the linked grids automatically stay in sync.

Simple Data Grid

To generate a data grid, place a TableGrid in a Report or SubReport DetailBand. Add data-aware objects, such DBText, DBMemo, DBImage to each Cell.

Download example Simple Data Grid

Design Actions

From the report designer, the following mouse actions are available:

  • Select Grid – click inside edge of left, top corner
  • Resize Grid – drag right-bottom sizing handle
  • Resize Grid Width – width drag right-middle sizing handle
  • Resize Grid Height – height drag bottom-middle sizing handle
  • Select Cell –  click inside a cell
  • Multi-select – shift-click each cell
  • Select Row – click left inside edge of row
  • Select Col –  click top inside edge of column
  • Resize Col – drag the column border
  • Resize Row – drag the row border

The report tree can also be used to select grid, row, and cell objects

The grid context menu can be accessed by pressing right mouse button over any cell. The Row and Col items have subitems for Select, Add, Insert, and Delete. The Cell menu item has subitems for Merge and Divide.

Code Access

To access/modify a grid via code, the following properties and methods are available:

// access cells
myTableGrid.Cells[RowIndex, ColIndex]
myTableGrid.Rows[RowIndex].Cells[ColIindex]
myTableGrid.Cols[ColIndex].Cells[RowIndex]

//add rows
myTableGrid.Rows.Add
myTableGrid.RowCount := myTableGrid.RowCount + X

//insert rows
myTableGrid.Rows.Insert(RowIndex)

//remove rows
myTableGrid.Rows.Remove(RowIndex);
myTableGrid.RowCount := myTableGrid.RowCount - X
// move rows 

myTableGrid.Rows[RowIndex].RowIndex := X

// add cols 
myTableGrid.Cols.Add;
myTableGrid.ColCount := myTableGrid.ColCount + X

// insert cols 
myTableGrid.Cols.Insert(RowIndex);

// remove cols 
myTableGrid.Cols.Remove(RowIndex);
myTableGrid.ColCount := myTableGrid.ColCount - X

//move cols 
myTableGrid.Cols[ColIndex].ColIndex := X

// access cell objects
myCell.Objects[ObjectIndex]

// add object to cell
myObject.Parent := myCell;