RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TDrawGrid.ColCount Property

Specifies the number of columns in the grid.

Pascal
property ColCount: Longint;
C++
__property Longint ColCount;

Read ColCount to determine the number entries in the ColWidths array. Set ColCount to add or delete columns at the righthand side of the grid. The value of ColCount includes any fixed columns at the left of the grid as well as the scrollable columns in the body of the grid.  

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!