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