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
Collection of columns displayed in the grid. Each column defines how data is displayed and formatted.Grid.Columns.Add('Name');
Grid.Columns.Add('Email');
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;
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;
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;
Special column displayed as the leftmost column showing row state indicators (browse, edit, insert).Grid.Indicator.Visible := True;
Grid.Indicator.Width.Value := 20;
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;
Default text rendering properties for all cells. Defines font, alignment, and formatting.Grid.Cells.Font.Name := 'Arial';
Grid.Cells.Font.Size := 10;
Controls whether the entire grid is read-only. When true, no cells can be edited.Grid.ReadOnly := True; // Disable all editing
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;
Edge spacing around the entire grid content.Grid.Margins.Left := 10;
Grid.Margins.Top := 10;
The virtual data source bound to this grid. Provides the data displayed in rows.Grid.Data := VirtualDBData1; // Bind to database
Reference to the currently active row group (for master-detail scenarios).
Key Methods
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);
Returns true if cell editing can be started in the current context.if Grid.CanStartEditor then
// Start editing
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)
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');
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)
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
Creates a new expander render instance for master-detail functionality.var
Expander: TExpanderRender;
begin
Expander := Grid.NewExpander;
// Configure expander
end;
Automatically scrolls the grid to make the selected cell visible.Grid.Selected.Row := 100;
Grid.AutoScroll; // Scroll to row 100
Attempts to select the first selectable column.
Returns the maximum bottom Y coordinate of all grid content.var
Bottom: Single;
begin
Bottom := Grid.MaxBottom;
end;
Refreshes the grid with new or updated data source.Grid.RefreshData(NewVirtualData);
Interaction Methods
Mouse(AState, AWidth, AHeight)
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;
Handles keyboard events for navigation and editing.var
State: TKeyState;
begin
// Key state populated by framework
Grid.Key(State);
end;
Events
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;
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;
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;
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;
The TGridScrolling class provides several scrolling modes:
Scrolling only works with finger-touch gestures.Grid.Scrolling.Mode := TScrollingMode.Touch;
Scrolling works with left-button mouse drag.Grid.Scrolling.Mode := TScrollingMode.Mouse;
Scrolling works with both touch and mouse.Grid.Scrolling.Mode := TScrollingMode.Both;
Scrolling is disabled.Grid.Scrolling.Mode := TScrollingMode.None;
type
TScrollDirection = (Normal, Inverted, Disabled);
- Normal: Standard scrolling behavior
- Inverted: Reverse scrolling direction
- Disabled: Scrolling disabled for that axis