AutoSize列标题

时间:2015-07-08 13:52:47

标签: delphi firemonkey stringgrid

我有一个链接到FDMemTable的字符串网格,当我第一次运行AutoSize程序(我添加到它的类助手)时,一切都很完美。

之后,当我尝试重新打开FDMemTable时,我的Header会回到默认大小,但其他行保持不变。

我的程序如下:

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;

如果我手动调整列的大小,它会恢复正常。

我正在使用XE7及其多设备应用程序(FireMonkey)

2 个答案:

答案 0 :(得分:0)

这看起来像Delphi XE7 Update 1的bug。

在Delphi XE8上,您的代码运行良好。 enter image description here

在Delphi XE7 Update1上看起来很奇怪。 enter image description here

答案 1 :(得分:0)

通过更改FDMemTable(到任何字段),它恢复正常。

我刚刚调用了我的订单程序。