lazarus - 为什么加载网格时 TStringGrid 列标题单元格中的单元格属性会发生变化?

标签 lazarus tstringgrid text-rendering

我正在运行 Lazarus v0.9.30(32 位编译器)。

这个问题是之前的question的延伸。我的。

上一个问题围绕如何更改我在运行时加载到标准 TStringGrid 的 TGridColumns 对象中的文本方向。解决方案涉及重写字符串网格的 DrawCellText 事件。

我的问题是这样的。当我尝试加载 TStringGrid 时,我发现文本方向保持不变,但列单元格高度变回默认高度。

我用来加载网格的代码如下所示。

procedure TTmMainForm.vLoadWorldScoutGrid;
var
  aMember : TTmMember;
  anIndex1: integer;
  anIndex2: integer;
begin
  //Clear the string grid and set the row count to 1 to take into account the fixed row.
  SgWorldScout.Clear;
  SgWorldScout.RowCount := 1;

  for anIndex1 := 0 to Pred(FManager.Members.Count) do
  begin
    //Add a new row to the string grid.
    SgMembers.RowCount := SgMembers.RowCount + 1;

    //Get the TTmMember object from the collection.
    aMember := TTmMember(FManager.Members.Items[anIndex1]);

    //Populate the row cells in the string grid.
    SgMembers.Cells[0, SgMembers.RowCount - 1] := aMember.stMemberNumber;
    SgMembers.Cells[1, SgMembers.RowCount - 1] := aMember.stPatrol;
    SgMembers.Cells[2, SgMembers.RowCount - 1] := aMember.stSurname;
    SgMembers.Cells[3, SgMembers.RowCount - 1] := aMember.stFirstName;

    //Add the TTmMember object to every row cell.
    for anIndex2 := 0 to SgMembers.ColCount - 1 do
      SgMembers.Objects[anIndex2, SgMembers.RowCount - 1] := aMember;
  end; {for}}

  vSetWorldScoutGridPushbuttons;
end; 

我怀疑当我调用“SgWorldScout.Clear”时,字符串网格单元的属性可能会随着默认的 DrawCellText 事件被调用而重置/修改,这将解释单元高度的变化。不确定为什么文本方向也没有改变。有人能够解释 DrawCellText 事件的行为以及为什么我会看到这个吗?

最佳答案

Clear设置RowCountColCount正如您所怀疑的那样,为 0。那么 RowHeights 就很合乎逻辑了也被清除,因为当你有RowCount时设置为 0 则没有要存储的高度。如果您只想清除并添加非固定行,则只需设置 RowCount到 1 而不清除整个网格。因此,按如下方式修改您的代码:

procedure TTmMainForm.vLoadWorldScoutGrid;
var
  aMember : TTmMember;
  anIndex1: integer;
  anIndex2: integer;
begin
  // set the row count to 1 to keep the fixed row along with its settings
  SgWorldScout.RowCount := 1;

  for anIndex1 := 0 to Pred(FManager.Members.Count) do
  ...
end;

关于lazarus - 为什么加载网格时 TStringGrid 列标题单元格中的单元格属性会发生变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9662367/

相关文章:

delphi - 在Delphi中尝试除了尝试还是最终尝试

compiler-errors - Lazarus IDE-编译失败: Cannot open include file

compiler-errors - indy-10.2.0.1/fpc/IdStackUnix.pas(610,19)错误: Identifier not found “socket”

delphi - 在 Delphi TStringGrid 中检测单选与多选

python - PIL 切断了字母的顶部

c++ - 硬件加速 Unicode 文本渲染

html - HTML 表格中的垂直(旋转)文本

mysql - Lazarus 控制台应用程序无法连接到 mysql - ubuntu

delphi - 如何在firemonkey TStringGrid中完成编辑后立即将数据发布到数据库

delphi - StringGrid 的 OnSetEditText 事件有什么作用?