StringGridRows (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example displays a string grid, a list box, and a button on a form. When the application runs, strings are put in the cells of the first row of the string grid. When you click the button, the strings in the current row of the grid are displayed in the list box. Note that when the grid contains an empty cell, the list box has a corresponding empty string.

Code

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  ListBox1->Items = StringGrid1->Rows[StringGrid1->Row];
}

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{

  StringGrid1->Cells[1][0] = "Column 1";
  StringGrid1->Cells[2][0] = "Column 2";
  StringGrid1->Cells[3][0] = "Column 3";
  StringGrid1->Cells[4][0] = "Column 4";
  StringGrid1->Cells[0][1] = "Row 1";
  StringGrid1->Cells[1][1] = "Object";
  StringGrid1->Cells[2][1] = "Pascal";
  StringGrid1->Cells[3][1] = "is";
  StringGrid1->Cells[4][1] = "excellent";
  StringGrid1->Cells[0][2] = "Row 2";
  StringGrid1->Cells[1][2] = "Delphi";
  StringGrid1->Cells[2][2] = "is";
  StringGrid1->Cells[4][2] = "RAD";

}

Uses