Hi,
I've downloaded the latest version of the TMS FMX UI Pack.
Because the standard AutoSizeColumns method doesn't seem to work optimal, I've written my own "MyAutoSizeColumns" method in the descendant Class.
In our descendant Class the First column is always hidden and holds specific data.
With the new version of the TMSFMXGrid, all sizing goes completely wrong.
For now I have reverted the change in TMSCustomGrid.pas and everything went back to normal.
cw := ColumnWidths[c]; //JJ ColumnWidths[DisplToRealColumn(c)];
But maybe I'm doing something wrong in my calculations.
This my code:
function TMyGrid.MyAutoSizeColumn(AColumn: Integer): Single;
var
idx: Integer;
begin
Result := 40;
if Assigned(Canvas) then
begin
for idx := 0 to RowCount - 1 do
begin
Result := Max(Result, 25 + Canvas.TextWidth(Cells[AColumn, idx]));
end;
end;
ColumnWidths[AColumn] := Result;
end;
procedure TMyGrid.MyAutoSizeColumns;
var
idx : Integer;
w : Single;
cols: Integer;
begin
w := 0;
// -- First make sure all columns fit
for idx := 0 to ColumnCount - 1 do
begin
w := w + MyAutoSizeColumn(idx);
end;
// -- If there is space left
if w < Width then
begin
cols := 0;
for idx := 0 to ColumnCount - 1 do
begin
if Columns[idx].ColumnType <> ctCheckBox then
Inc(cols);
end;
// -- Calculate extra width per column (substract width vertical scrollbar)
if cols = 0 then
w := 0
else
w := (Width - w - 30) / cols;
// -- Add extra width to every column
for idx := 0 to ColumnCount - 1 do
begin
if Columns[idx].ColumnType <> ctCheckBox then
ColumnWidths[idx] := ColumnWidths[idx] + w;
end;
end;
UpdateGrid;
end;