3

我正在使用 Lazarus 0.9.30.2。我有一个标准的 TForm,上面有一个标准的 TStringGrid。字符串网格在设计时没有列或行。在 Object Inspector 中设置了以下值。

ColCount = 0
Columns = 0
FixedCols = 0
FixedRows = 0
RowCount = 0

我想在运行时添加一些 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.                                                                                                                                              
4

1 回答 1

4

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

如何解决它:

我怀疑这个TCustomGrid.AdjustCount程序,但这只是一个疯狂的猜测和题外话。

于 2012-03-01T00:27:09.857 回答