Ganz einfach (Getestet mit 10.1 Berlin):
Code:
procedure TForm1.AutoSizeCol(Grid: TStringGrid; Column: integer);
var
i: integer;
W, WMax : Single;
begin
WMax := 0;
for i := 0 to (Grid.RowCount - 1) do begin
W := Grid.Canvas.TextWidth(Grid.Cells[Column, i]);
if W > WMax then
WMax := W;
end;
Grid.Columns[Column].Width := WMax + 8;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
for i := 0 to StringGrid1.ColumnCount - 1 do
AutoSizeCol(StringGrid1, i);
end;