【问题标题】:Add stringgrid column at runtime在运行时添加 stringgrid 列
【发布时间】:2017-03-08 21:05:12
【问题描述】:

我在网上找到了许多解决方案,但它们都不起作用,因为StringGrid1.ColumnCount peoperty 是只读的。我正在使用 Delphi 10 Seattle。

我有一个 StringGrid1,我需要在运行时添加列。具体来说,我必须根据 TList 的大小添加列。特别是:

var a: TList<double>;
begin

 //fill the TList...

 for i := 0 to a.Count - 1 do
  begin
   StringGrid1.AddColumn(); //how can I do this?
  end;

end;

我发现在 Lazarus 上这很容易(当然它有 FPC),但在 Delphi 上我真的不知道该怎么做。我正在研究 Firemonkey。

【问题讨论】:

  • "StringGrid1.ColCount 属性是只读的" - 这仅在 FireMonkey 中是正确的。 ColCount 属性在 VCL 中是读/写的。此外,在 FMX 中,没有 ColCount 属性,它实际上被命名为 ColumnCount。下次请说明您使用的是哪个框架。
  • 很难知道你在说什么
  • 我没有很好地解释这个问题,但我只需要在 TStringGrid 中添加一列(TStringColums)。

标签: delphi firemonkey delphi-10-seattle


【解决方案1】:

使用网格的AddObject()InsertObject() 方法添加所需TColumn 派生类的对象实例,例如TStringColumn。列对象将被添加到网格的Columns 数组中。 ColumnCount 属性只返回数组中的列数,这就是为什么它是只读的。

【讨论】:

  • StringGrid1.AddObject(TStringColumn.Create(StringGrid1));
猜你喜欢
  • 1970-01-01
  • 2014-11-18
  • 2019-11-02
  • 2011-10-21
  • 2010-11-02
  • 1970-01-01
  • 1970-01-01
  • 2017-06-25
  • 1970-01-01
相关资源
最近更新 更多