Skip to main content

Overview

TRowGroup is a comprehensive grid band class that paints headers, cell rows, and footers. It provides the main grid functionality including data binding, column management, selection, scrolling, and editing. It supports hierarchical master-detail structures through sub-grids.

Key Properties

Columns
TColumns
Collection of columns displayed in the grid. Each column defines how data is displayed and formatted.
Grid.Columns.Add('Name');
Grid.Columns.Add('Email');
Rows
TRows
The rows band that displays data cells. Contains all row-related properties like height, spacing, and data source.
Grid.Rows.Height.Value := 25;
Grid.Rows.Data := MyVirtualData;
Header
TColumnHeaderBand
The header band that displays column headers. Controls the appearance and behavior of the column header row.
Grid.Header.Height.Value := 30;
Grid.Header.Visible := True;
Headers
TGridBands
Collection of additional header bands. Allows multiple header rows above the main header.
var
  ExtraHeader: TGridBand;
begin
  ExtraHeader := Grid.Headers.Add;
  ExtraHeader.Height.Value := 25;
end;
Collection of footer bands. Allows adding footer rows below the data rows.
var
  FooterBand: TGridBand;
begin
  FooterBand := Grid.Footer.Add;
  FooterBand.Height.Value := 25;
end;
Indicator
TIndicator
Special column displayed as the leftmost column showing row state indicators (browse, edit, insert).
Grid.Indicator.Visible := True;
Grid.Indicator.Width.Value := 20;
Selected
TGridSelection
Selection properties defining which cells or rows are selected and how they appear.
Grid.Selected.Column := Grid.Columns[0];
Grid.Selected.Row := 5;
Grid.Selected.Format.Brush.Color := clHighlight;
Cells
TTextRender
Default text rendering properties for all cells. Defines font, alignment, and formatting.
Grid.Cells.Font.Name := 'Arial';
Grid.Cells.Font.Size := 10;
ReadOnly
Boolean
default:"false"
Controls whether the entire grid is read-only. When true, no cells can be edited.
Grid.ReadOnly := True; // Disable all editing
Scrolling
TGridScrolling
Scrolling configuration for mouse and touch interactions.
Grid.Scrolling.Mode := TScrollingMode.Both;  // Enable mouse and touch
Grid.Scrolling.Horizontal := TScrollDirection.Normal;
Grid.Scrolling.Vertical := TScrollDirection.Normal;
Margins
TMargins
Edge spacing around the entire grid content.
Grid.Margins.Left := 10;
Grid.Margins.Top := 10;
Data
TVirtualData
The virtual data source bound to this grid. Provides the data displayed in rows.
Grid.Data := VirtualDBData1;  // Bind to database
Current
TRowGroup
Reference to the currently active row group (for master-detail scenarios).

Key Methods

CellRect(AColumn, ARow)
TRectF
Returns the rectangle coordinates of the specified cell.
var
  R: TRectF;
begin
  R := Grid.CellRect(Grid.Columns[0], 5);
  // R contains the rectangle of the first column, row 5
end;
CheckColumnsWidth(APainter, Forced, AWidth)
Calculates and sets column widths based on content. Use Forced = True to recalculate all columns.
Grid.CheckColumnsWidth(Grid.Painter, True, Grid.Width);
PrepareColumns(APainter, ALeft, ARight)
Prepares columns for painting by calculating positions and widths.
Grid.PrepareColumns(Grid.Painter, 0, Grid.Width);
CanStartEditor
Boolean
Returns true if cell editing can be started in the current context.
if Grid.CanStartEditor then
  // Start editing
CanEditRender(AColumn)
Boolean
Returns true if the specified column can be edited (considering ReadOnly flags).
if Grid.CanEditRender(Grid.Columns[0]) then
  ShowMessage('Column can be edited');
RenderHit(AColumn, ARow, X, Y)
Boolean
Tests if a point (X, Y) hits a render element in the specified cell.
if Grid.RenderHit(Grid.Columns[0], 5, Mouse.X, Mouse.Y) then
  ShowMessage('Hit render element');
SelectedContains(X, Y)
Boolean
Returns true if the point (X, Y) is within the selected cell or range.
if Grid.SelectedContains(Mouse.X, Mouse.Y) then
  ShowMessage('Point is in selection');
ToggleDetail(Sender, ARow)
Boolean
Toggles the visibility of detail (sub-grid) for the specified row. Used in master-detail scenarios.
Grid.ToggleDetail(nil, 5); // Toggle detail for row 5
NewExpander
TExpanderRender
Creates a new expander render instance for master-detail functionality.
var
  Expander: TExpanderRender;
begin
  Expander := Grid.NewExpander;
  // Configure expander
end;
AutoScroll
Automatically scrolls the grid to make the selected cell visible.
Grid.Selected.Row := 100;
Grid.AutoScroll;  // Scroll to row 100
TrySelectColumn
Attempts to select the first selectable column.
Grid.TrySelectColumn;
MaxBottom
Single
Returns the maximum bottom Y coordinate of all grid content.
var
  Bottom: Single;
begin
  Bottom := Grid.MaxBottom;
end;
RefreshData(AData)
Refreshes the grid with new or updated data source.
Grid.RefreshData(NewVirtualData);

Interaction Methods

Mouse(AState, AWidth, AHeight)
Boolean
Handles mouse events (move, click, double-click, wheel). Returns true if the event was handled.
var
  State: TMouseState;
begin
  // Mouse state populated by framework
  Grid.Mouse(State, Grid.Width, Grid.Height);
end;
Key(AState)
Handles keyboard events for navigation and editing.
var
  State: TKeyState;
begin
  // Key state populated by framework
  Grid.Key(State);
end;

Events

OnNewDetail
TNewDetailEvent
Event triggered when a new detail (sub-grid) is created for master-detail functionality.
procedure TForm1.GridNewDetail(const Sender, NewGroup: TRowGroup);
begin
  // Configure the new detail grid
  NewGroup.Columns.Add('Detail Column 1');
  NewGroup.Columns.Add('Detail Column 2');
end;

// Assign event
Grid.OnNewDetail := GridNewDetail;
OnChangedSelected
TNotifyEvent
Event triggered when the selected cell changes.
procedure TForm1.GridSelectionChanged(Sender: TObject);
begin
  ShowMessage(Format('Selected: Column %d, Row %d',
    [Grid.Selected.Column.Index, Grid.Selected.Row]));
end;

// Assign event
Grid.OnChangedSelected := GridSelectionChanged;

Usage Examples

Basic Grid Setup

begin
  // Configure columns
  Grid.Columns.Add('ID');
  Grid.Columns.Add('Name');
  Grid.Columns.Add('Email');
  
  // Configure rows
  Grid.Rows.Height.Value := 25;
  Grid.Rows.Data := MyVirtualData;
  
  // Configure header
  Grid.Header.Visible := True;
  Grid.Header.Height.Value := 30;
  
  // Configure indicator
  Grid.Indicator.Visible := True;
end;

Master-Detail Grid

procedure TForm1.SetupMasterDetail;
var
  ExpanderCol: TColumn;
begin
  // Add expander column for master rows
  ExpanderCol := Grid.Columns.Add;
  ExpanderCol.Width.Value := 30;
  ExpanderCol.Render := Grid.NewExpander;
  
  // Handle detail grid creation
  Grid.OnNewDetail := GridNewDetail;
end;

procedure TForm1.GridNewDetail(const Sender, NewGroup: TRowGroup);
begin
  // Configure detail grid
  NewGroup.Columns.Add('Detail ID');
  NewGroup.Columns.Add('Detail Name');
  NewGroup.Rows.Data := GetDetailData(Sender.Selected.Row);
end;

procedure TForm1.ToggleDetailForRow(RowIndex: Integer);
begin
  Grid.ToggleDetail(nil, RowIndex);
end;

Cell Selection

begin
  // Select a specific cell
  Grid.Selected.Column := Grid.Columns[2];
  Grid.Selected.Row := 10;
  Grid.AutoScroll;  // Scroll to make it visible
  
  // Handle selection changes
  Grid.OnChangedSelected := procedure(Sender: TObject)
  begin
    with Grid.Selected do
      ShowMessage(Format('Row: %d, Column: %s', 
        [Row, Column.Header.Text]));
  end;
end;

Scrolling Configuration

begin
  // Enable touch and mouse scrolling
  Grid.Scrolling.Mode := TScrollingMode.Both;
  
  // Set scroll directions
  Grid.Scrolling.Horizontal := TScrollDirection.Normal;
  Grid.Scrolling.Vertical := TScrollDirection.Normal;
  
  // Disable horizontal scrolling
  Grid.Scrolling.Horizontal := TScrollDirection.Disabled;
end;

Custom Headers and Footers

var
  ExtraHeader, FooterBand: TGridBand;
begin
  // Add extra header
  ExtraHeader := Grid.Headers.Add;
  ExtraHeader.Height.Value := 25;
  
  // Add footer with totals
  FooterBand := Grid.Footer.Add;
  FooterBand.Height.Value := 30;
end;

Read-Only Grid

begin
  // Make entire grid read-only
  Grid.ReadOnly := True;
  
  // Or make specific columns read-only
  Grid.Columns[0].ReadOnly := True;
end;

Auto-Sizing Columns

begin
  // Force recalculation of all column widths
  Grid.CheckColumnsWidth(Grid.Painter, True, Grid.Width);
end;

Scrolling Modes

The TGridScrolling class provides several scrolling modes:
Scrolling only works with finger-touch gestures.
Grid.Scrolling.Mode := TScrollingMode.Touch;

Scroll Directions

type
  TScrollDirection = (Normal, Inverted, Disabled);
  • Normal: Standard scrolling behavior
  • Inverted: Reverse scrolling direction
  • Disabled: Scrolling disabled for that axis

Build docs developers (and LLMs) love