我在另一个 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));
或在设计时使用项目设计器
关于delphi - 如何在 Delphi XE3、Firemonkey2 中更新 TStringGrid 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13309853/