How can I auto size the rows and columns to fit the text please.
I found this VCL code
procedure TForm7.AutoSizeColumns(Grid: TStringGrid);
var
i, j: Integer;
ColumnWidth: Integer;
begin
for j := 0 to Grid.ColCount - 1 do
begin
ColumnWidth := Round(Grid.Canvas.TextWidth(Grid.Cells[j, 0]));
for i := 1 to Grid.RowCount - 1 do
begin
if Round(Grid.Canvas.TextWidth(Grid.Cells[j, i])) > ColumnWidth then
ColumnWidth := Round(Grid.Canvas.TextWidth(Grid.Cells[j, i]));
end;
Grid.ColWidths[j] := ColumnWidth + 10; // Adding some padding
end;
end;
I get ERROR
Uncaught TypeError: Cannot read properties of null (reading 'TextWidth') | TypeError: Cannot read properties of null (reading 'TextWidth') at Object.AutoSizeColumns