{ TStringGridHelper }
TStringGridHelper = class helper for TStringGrid
protected
procedure AutoSizeRow(aRow: integer);
end;
{ TStringGridHelper }
procedure TStringGridHelper.AutoSizeRow(aRow: integer);
var
aCanvas: TCanvas;
aCol, maxRowHeight:integer;
aText: String;
textRect: TRect;
begin
aCanvas := GetWorkingCanvas(Canvas);
maxRowHeight := DefaultRowHeight;
for aCol:=0 to ColCount-1 do begin
aText := Cells[aCol,aRow];
textRect := Rect(0, 0, ColWidths[aCol], MaxInt);
DrawText(aCanvas.Handle, PChar(aText), Length(aText), textRect, DT_CALCRECT or DT_WORDBREAK);
if maxRowHeight < textRect.Height then
maxRowHeight := textRect.Height
end;
if aCanvas<>Canvas then FreeWorkingCanvas(aCanvas);
RowHeights[aRow] := maxRowHeight+2;
end;