RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TStringGrid.Cells Property

Lists the strings for each cell in the grid.

Pascal
property Cells [ACol, ARow: Integer]: string;
C++
__property AnsiString Cells[int ACol, ARow];

Use Cells to access the string within a particular cell. ACol is the column coordinate of the cell, and ARow is the row coordinate of the cell. The first row is row zero, and the first column is column zero. 

The ColCount and RowCount property values define the size of the array of strings. 

To access the objects associated with the strings in the Cells array, use the Objects property.  

C++ Examples: 

 

/*
This code fills each cell with a number. The numbers are
arranged in consecutive order by rows.  Notice that even
cells in the fixed rows and columns are altered.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  int I, J, K;

  K = 0;

  for (I = 0; I < StringGrid1->ColCount; I++)
    for (J = 0; J < StringGrid1->RowCount; J++)
      StringGrid1->Cells[I][J] = IntToStr(++K);
}

 

Delphi Examples: 

{
This code fills each cell with a number. The numbers are
arranged in consecutive order by rows.  Notice that even
cells in the fixed rows and columns are altered.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  I, J, K : Integer;
begin
  K := 0;
  with StringGrid1 do
    for I := 0 to ColCount - 1 do
      for J:= 0 to RowCount - 1 do
        begin
          K := K + 1;
          Cells[I,J] := IntToStr(K);
        end;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!