delphi - 如何在 Delphi XE3、Firemonkey2 中更新 TStringGrid 单元格

标签 delphi firemonkey delphi-xe3

我在另一个 question 中看到过这个问题。以前,所以知道这不仅仅是我......如果我打开一个新的 FireMonkey2 HD 应用程序,添加一个 TButton 和 TStringGrid,然后将其添加到单击事件上的按钮,当我单击按钮时网格中什么也没有发生!

procedure TForm33.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  for i:= 0 to 6 do
   begin
     StringGrid1.Cells[0,i] := 'Row:' + IntToStr(i);
   end;
   stringgrid1.UpdateColumns;
   stringgrid1.SetFocus;
 end;    

有什么想法吗? PS 我也尝试过使用 TStringGrid.OnGetValue,但它仍然不会在 StringGrid 中显示任何内容。

进一步研究 TStringGrid 源代码后,C 为零,因此单元格永远不会被设置。

procedure TStringGrid.SetValue(Col, Row: Integer; const Value: TValue);
var
  C: TColumn;
begin
  C := Columns[Col];
  if Assigned(C) then
  begin
    C.UpdateRowCount(RowCount);
    C.SetCells(Row, Value);
  end;

我发现“原始”StringGrid 中没有列,那么如何添加它们?有一个 r+w RowCount 属性,但 ColCount 是只读的...

最佳答案

您必须至少向 TStringGrid 添加一列为了向单元格添加数据,您可以在运行时执行此操作

StringGrid1.AddObject(TStringColumn.Create(Self)); 

或在设计时使用项目设计器

enter image description here

关于delphi - 如何在 Delphi XE3、Firemonkey2 中更新 TStringGrid 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13309853/

相关文章:

Delphi TGIFImage 动画问题与某些 GIF 查看器有关

Delphi:在多行文本组件(例如 TMemo 或 TRichEdit)中使用 TextHint

delphi - TeeChart:在当前鼠标位置显示系列值的快速方法

delphi - 停止异常 Delphi 10.1

delphi - Delphi中从TWebRequest获取文件

android - 从 Android 本地存储的 client-cert.pem 文件获取 SSL 证书到期日期

delphi - 如何在我的 Delphi 应用程序中使用嵌入式 Firebird

delphi - Delphi XE3 中缺少 VCL 样式

Delphi Frame继承的属性不存在

delphi - firemonkey 移动网格与实时绑定(bind) - 在运行时更改 TextCell 文本颜色 XE5