procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
var
i, x, y: Integer;
begin
if gdFixed in aState then
Exit;
if not (ARow in [1, 3]) then
Exit;
{Draw row 1 with text from cell 1,1 spanning all cells in the row}
with Sender as TStringGrid do
begin
{Extend rect to include grid line on right, if not last cell in row}
if aCol < Pred(ColCount) then
aRect.Right := aRect.Right + GridlineWidth;
{Figure out where the text of the first cell would start relative to the
current cells rect}
y := aRect.Top + 2;
x := aRect.Left + 2;
for i := 1 to aCol - 1 do
x := x - ColWidths[i] - GridlineWidth;
{Paint cell pale yellow}
Canvas.Brush.Color := $7FFFFF;
Canvas.Brush.Style := bsSolid;
Canvas.FillRect(aRect);
{Paint text of cell 1,1 clipped to current cell}
Canvas.TextRect(aRect, x, y, 'A rather long line which will span cells');
end;
end;