Skip to main content
Table of Contents

TTMSFNCDataGrid.MergeCells Method

Merges a rectangular block of cells into a single display cell.

API unit family: TMSFNCDataGrid Declaring type: TTMSFNCDataGrid Inherited from: TTMSFNCCustomDataGrid

Syntax

FMX.TMSFNCDataGrid.hppPascalC++
procedure MergeCells(AColumn, ARow, AColumnCount, ARowCount: Integer);
void __fastcall MergeCells(int AColumn, int ARow, int AColumnCount, int ARowCount);

Parameters

Name Description
AColumn Zero-based starting column of the merge range.
ARow Zero-based starting row of the merge range.
AColumnCount Number of columns to include in the merge.
ARowCount Number of rows to include in the merge.

Usage examples

Merge a rectangular range of cells, then split it back

Combine multiple cells into one visual cell using MergeCells / MergeRange; reverse the operation with SplitCell.

Merge a rectangular range of cells, then split it backPascalC++
procedure TForm1.FormCreate(Sender: TObject);
begin
  Grid.LoadFromCSVData('CARS.csv');
  Grid.Options.Selection.Mode := gsmCellRange;

  // Arguments are (AColumn, ARow, AColumnCount, ARowCount): the top-left anchor
  // plus the span. Merge a 3-column x 1-row banner starting at column 1, row 3.
  Grid.MergeCells(1, 3, 3, 1);

  // Merge a 2-column x 4-row block starting at column 7, row 2.
  Grid.MergeCells(7, 2, 2, 4);
end;

procedure TForm1.MergeSelectionClick(Sender: TObject);
begin
  Grid.MergeRange(Grid.Selection);
end;

procedure TForm1.SplitSelectedCellClick(Sender: TObject);
begin
  Grid.SplitCell(Grid.Selection.StartCell);
end;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  Grid->LoadFromCSVData("CARS.csv");
  Grid->Options->Selection->Mode = gsmCellRange;

  // Arguments are (AColumn, ARow, AColumnCount, ARowCount): the top-left anchor
  // plus the span. Merge a 3-column x 1-row banner starting at column 1, row 3.
  Grid->MergeCells(1, 3, 3, 1);

  // Merge a 2-column x 4-row block starting at column 7, row 2.
  Grid->MergeCells(7, 2, 2, 4);
}

void __fastcall TForm1::MergeSelectionClick(TObject *Sender)
{
  Grid->MergeRange(Grid->Selection);
}

void __fastcall TForm1::SplitSelectedCellClick(TObject *Sender)
{
  Grid->SplitCell(Grid->Selection.StartCell);
}

Read the related guide