delphifiremonkeystringgrid

AutoSize Columns Header


I have a string grid that's linked to a FDMemTable and when I run the AutoSize procedure (that I added to its class helper) for the first time everything is perfect.

After that, when I try reopening the FDMemTable my Header goes back to the default size but the other lines stay the same.

My procedure is as follows:

procedure TStringGridHelper.AutoSizeCols;
var
  i, W, WMax: integer;
  Column : Integer;
begin
  for Column := 0 to Self.ColumnCount-1 do
  begin
    if Self.ColumnByIndex(Column).Width > 0 then
    begin
      WMax := Round(Canvas.TextWidth(Self.ColumnByIndex(Column).Header));
      for i := 0 to (Self.RowCount - 1) do begin
        W := Round(Canvas.TextWidth(Self.Cells[Column, i]));
        if W > WMax then
          WMax := W;
        if WMax > SizeMax then
        begin
          WMax := SizeMax;
          Break;
        end;
      end;
      Self.ColumnByIndex(Column).Width := WMax + 10;
    end;
  end;
end;

If I resize a column manually it goes back to normal.

I'm using XE7 and its a Multi-Device Application (FireMonkey)


Solution

  • By Changing the FDMemTable's (to any field) it got back to normal.

    I just called my Order Procedure.