AutoSize Title Header

I have a row grid associated with an FDMemTable and when I run the AutoSize procedure (which I added to its class helper) everything is perfect the first time.

After that, when I try to reopen the FDMemTable, my title reverts to the default size, but the rest of the lines remain the same.

My procedure is this:

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 the column manually, it goes back to normal.

I am using XE7 and its Multi-Device Application (FireMonkey)

+3


source to share


2 answers


By changing the FDMemTable (to any field) it got back to normal.



I just named my ordering procedure.

0


source


It looks like a Delphi XE7 Update 1 bug.

In Delphi XE8, your code works well. enter image description here



It looks strange in Delphi XE7 Update1. enter image description here

0


source







All Articles