Site icon Learn C++

This Is How To Use The VCL StringGrid Component In A C++ App

C++ Builder has a lot of great components you can use to create a C++ app and StringGrid (TStringGrid) is one of these. A StringGrid  represents a grid control designed to simplify the handling of strings.

We can easily add a TStringGrid object to a form to represent textual data in a tabular format. StringGrid provides many properties to control the appearance of the grid, as well as events and methods that take advantage of the tabular organization of the grid in responding to user actions. StringGrid introduces the ability to associate an object with each string in the grid. These objects can encapsulate any information or behavior represented by the strings that are presented to the user.

What are the properties of TStringGrid?

ColCount and RowCount

ColCount specifies the number of columns in the grid. We can read Column Count to determine the number of entries in the Columns array or we can add or delete rows at the bottom of the grid.

RowCount specifies the number of rows in the grid, The value of RowCount includes the scrollable rows in the grid, but not the fixed row with the headers. We can read RowCount to determine the number of rows in the grid or we can set RowCount to add or delete rows at the bottom of the grid.

Here is a example below,

[crayon-66dcf5e4a4327344556839/]

Cells Array

Cells array lists the strings for each cell in the grid. We can 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. Each grid member is String member which means they are UnicodeString, can be used with worldwide languages.

[crayon-66dcf5e4a4332664721071/]

Col and Row

Col property is the column number of the selected cell, or -1 if there is no cell selected.
Row is the number of the selected row.

[crayon-66dcf5e4a4336543469088/]

DefaultColWidth and DefaultRowHeight

A StringGrid Example on a VCL form

[crayon-66dcf5e4a433e594148263/]

You can download a free trial of C++ Builder right now.

Exit mobile version