在运行时动态添加列到 TStringGrid 时如何避免固定列?

use*_*918 4 fixed lazarus tstringgrid

我正在使用拉撒路 0.9.30.2。我有一个标准的 TForm,上面有一个标准的 TStringGrid。在设计时,字符串网格上没有列或行。在对象检查器中设置以下值。

ColCount = 0
Columns = 0
FixedCols = 0
FixedRows = 0
RowCount = 0
Run Code Online (Sandbox Code Playgroud)

我想在运行时添加许多 TGridColumns,并且已经能够这样做,但总是得到一个固定列,这是我不想要的。我已经编写了与下面的示例非常相似的代码来执行此操作。当我编译并运行它时,我得到以下结果。

在此输入图像描述

如何在运行时去掉固定列并保留剩余的列?

unit test;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids;

type
  TForm1 = class(TForm)
    SgGrid: TStringGrid;
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1; 

implementation

{$R *.lfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  GridColumn : TGridColumn;
  anIndex    : integer;
begin
  for anIndex := 0 to 5 do
    begin
      GridColumn := SgGrid.Columns.Add;
      GridColumn.Width := 50;
      GridColumn.Title.Caption := 'Col ' + inttostr(anIndex);
    end; {for}
end;

end.                                                                                                                                              
Run Code Online (Sandbox Code Playgroud)

TLa*_*ama 5

我认为这是一种功能(或者从另一个角度来看是错误)。如果在设计时您的字符串网格为空(0 列,0 行),则在运行时添加列时,以下属性将设置为默认的存储值。

如何解决它:

我怀疑这个TCustomGrid.AdjustCount程序,但这只是一个疯狂的猜测,与这里无关。

  • 你好@TLama ....我在发帖后又玩了一会儿,并确认了你在评论中所说的一切。在运行时,默认添加固定列。如果我在设计时将任何类型的列添加到网格中,则不会添加固定列。我最终做的是动态添加所有列,然后最后设置 'FixedCol := 0' (2认同)