如何更新Delphi XE3,Firemonkey2中的TStringGrid单元格

ser*_*tKK 3 delphi firemonkey delphi-xe3

我已经看到这个问题是另一个问题的一部分,所以知道它不能只是我......如果我打开一个新的FireMonkey2 HD应用程序,添加一个TButton和TStringGrid,然后将其添加到click事件的按钮上当我点击按钮时,网格中没有发生!

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;    
Run Code Online (Sandbox Code Playgroud)

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

进一步研究TStringGrid源代码后,C为零,因此Cell永远不会被设置.

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;
Run Code Online (Sandbox Code Playgroud)

我似乎在"处女"StringGrid中没有列,所以你如何添加它们?有一个r + w RowCount属性,但ColCount只读...

RRU*_*RUZ 5

您必须至少添加一列TStringGrid才能将数据添加到单元格,您可以在运行时执行此操作

StringGrid1.AddObject(TStringColumn.Create(Self)); 
Run Code Online (Sandbox Code Playgroud)

或者在设计时使用Items Designer

在此输入图像描述