Skip to main content

Overview

TRows is a grid band class that paints multiple rows of column cells. It includes support for hierarchical “rows-inside-rows” through the Children property, enabling master-detail row structures.

Key Properties

Height
TCoordinate
Default height for all rows in pixels. Individual row heights can be overridden using the Heights property.
Grid.Rows.Height.Value := 25; // 25 pixels per row
Heights[Index]
Single
Individual height for a specific row. Allows different rows to have different heights.
Grid.Rows.Heights[0] := 30;  // First row 30 pixels
Grid.Rows.Heights[1] := 20;  // Second row 20 pixels
Spacing
TCoordinate
Vertical spacing between rows in pixels.
Grid.Rows.Spacing.Value := 2; // 2 pixels between rows
Back
TFormat
Background formatting for all rows. Defines the default background color, gradient, and other visual properties.
Grid.Rows.Back.Brush.Color := clWhite;
Alternate
TAlternateFormat
Formatting properties for odd-numbered rows. Enables alternating row colors for better readability.
Grid.Rows.Alternate.Visible := True;
Grid.Rows.Alternate.Brush.Color := clSilver;
RowLines
TStroke
Stroke properties for horizontal lines between rows.
Grid.Rows.RowLines.Visible := True;
Grid.Rows.RowLines.Color := clGray;
Grid.Rows.RowLines.Width := 1;
Hover
TCellHover
Selection and formatting properties for the cell under the mouse cursor.
Grid.Rows.Hover.Visible := True;
Grid.Rows.Hover.Format.Brush.Color := clYellow;
Data
TVirtualData
The data source for the rows. Must be assigned to display data in the grid.
Grid.Rows.Data := MyVirtualData;
Children
TRowsBands
Collection of optional sub-rows for each row. Enables hierarchical row structures.
var
  SubRow: TGridBand;
begin
  SubRow := Grid.Rows.Children.Add;
  // Configure sub-row
end;
SubBands
TRowsBands
Collection of additional bands that can be displayed for each row.
VisibleColumns
TVisibleColumns
Internal property containing an array of all visible columns. Used for rendering.
YSpacing
Single
Calculated vertical spacing value used internally for rendering.

Key Methods

HeightOf(ARow)
Single
Returns the height of the specified row, taking into account custom heights or the default height.
var
  H: Single;
begin
  H := Grid.Rows.HeightOf(5); // Height of row 5
end;
TopOf(ARow)
Single
Returns the Y coordinate of the top edge of the specified row.
var
  Y: Single;
begin
  Y := Grid.Rows.TopOf(10); // Top position of row 10
end;
BottomOf(ARow)
Single
Returns the Y coordinate of the bottom edge of the specified row.
var
  Y: Single;
begin
  Y := Grid.Rows.BottomOf(10); // Bottom position of row 10
end;
RowAt(Y, AvailableHeight)
Integer
Returns the row index at the specified Y coordinate, or -1 if no row is found.
var
  RowIndex: Integer;
begin
  RowIndex := Grid.Rows.RowAt(100, Grid.Height);
end;
FirstVisible(AOffset)
Integer
Returns the index of the first visible row, optionally offset by the specified amount.
var
  FirstRow: Integer;
begin
  FirstRow := Grid.Rows.FirstVisible(Grid.Rows.Scroll.Y);
end;
AutoHeight(ARow)
Single
Calculates the automatic height for the specified row based on cell content.
var
  H: Single;
begin
  H := Grid.Rows.AutoHeight(5);
  Grid.Rows.Heights[5] := H;
end;
AllHeightsEqual
Boolean
Returns true if all rows have the same height.
Empty
Boolean
Returns true if there are no rows to display (data is empty).
MaxBottom
Single
Returns the Y coordinate of the bottom of the last row.
CalcDefaultHeight
Calculates and sets the default row height based on font size and cell formatting.
Grid.Rows.CalcDefaultHeight;
Clear
Clears all row-specific data and resets to initial state.
Grid.Rows.Clear;
Swap(A, B)
Swaps two rows at the specified indices.
Grid.Rows.Swap(0, 5); // Swap first and sixth rows

Usage Examples

Basic Row Configuration

begin
  // Set default row height
  Grid.Rows.Height.Value := 30;
  
  // Configure row spacing
  Grid.Rows.Spacing.Value := 1;
  
  // Enable row lines
  Grid.Rows.RowLines.Visible := True;
  Grid.Rows.RowLines.Color := clSilver;
end;

Alternating Row Colors

begin
  // Set default row background
  Grid.Rows.Back.Brush.Color := clWhite;
  
  // Configure alternate row formatting
  Grid.Rows.Alternate.Visible := True;
  Grid.Rows.Alternate.Brush.Color := RGB(240, 240, 240);
end;

Custom Row Heights

var
  i: Integer;
begin
  // Set individual row heights
  for i := 0 to Grid.Rows.Data.Count - 1 do
  begin
    if i mod 3 = 0 then
      Grid.Rows.Heights[i] := 40  // Every third row is taller
    else
      Grid.Rows.Heights[i] := 25;
  end;
end;

Auto-Height Rows

var
  i: Integer;
  H: Single;
begin
  // Calculate automatic height for each row
  for i := 0 to Grid.Rows.Data.Count - 1 do
  begin
    H := Grid.Rows.AutoHeight(i);
    Grid.Rows.Heights[i] := H;
  end;
end;

Row Hover Effect

begin
  // Enable hover highlighting
  Grid.Rows.Hover.Visible := True;
  Grid.Rows.Hover.Format.Brush.Color := clYellow;
  Grid.Rows.Hover.Format.Transparency := 128; // Semi-transparent
end;

Finding Rows

var
  RowIndex: Integer;
  Y: Single;
begin
  // Find row at mouse position
  RowIndex := Grid.Rows.RowAt(Mouse.Y, Grid.Height);
  if RowIndex >= 0 then
  begin
    // Get row position
    Y := Grid.Rows.TopOf(RowIndex);
    ShowMessage(Format('Row %d at Y=%g', [RowIndex, Y]));
  end;
end;

Hierarchical Rows

var
  DetailBand: TGridBand;
begin
  // Add sub-rows (detail rows)
  DetailBand := Grid.Rows.Children.Add;
  DetailBand.Height.Value := 20;
  
  // Check if children are visible for a specific row
  if Grid.Rows.IsChildrenVisible(nil, 5) then
    ShowMessage('Row 5 has visible children');
end;

Scrolling

The TRows class includes scroll support:
begin
  // Access scroll position
  ShowMessage('Vertical scroll: ' + FloatToStr(Grid.Rows.Scroll.Y));
  
  // Get first visible row after scrolling
  var FirstRow := Grid.Rows.FirstVisible(Grid.Rows.Scroll.Y);
end;

Build docs developers (and LLMs) love