FMXGrid AutoSizeColumns(True)

Good morning to all,
Ihave an autosizecolumns problem.

After populating the grid, i try to resize the all the columns according to the biggest cells width for each column with FMXGrid.AutoSizeColumns(True).
But this does not working ... the columns width still remain with the original width.

So i used this code as a workaround .. but works..

  var W,WS : Single:=0;
  for var C:=0 to SG1.ColumnCount - 1 do
  begin
    W:=0;
    WS:=SG1.Canvas.TextWidth(SG1.Cells[C,0]);
    for var R:=0 to SG1.RowCount - 1 do
    begin
      if WS>W then W:=WS + 10
    end;
    SG1.ColumnWidths[C]:=W;
  end;

OS Android 10, phone S10 +

It's possible i miss some setting ..

Thanks

Daniele

When are you calling AutoSizeColumns? The TMS FMX Grid is working with styles which need to be loaded first. You can force style loading with

TMSFMXGrid1.NeedStyleLookup;
TMSFMXGrid1.ApplyStyleLookup;

Hi Pieter,
thank you for fast reply.

All done ...Thank you again

Daniele

1 Like