C++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,

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.

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.

DefaultColWidth and DefaultRowHeight

A StringGrid Example on a VCL form

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


Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++Learn C++

How To Make Your C++ Compiler Fly Much Faster

C++C++11C++14C++17Introduction to C++Learn C++

This Is How To Join Two Wide Strings In Modern C++ Software

C++C++11C++14C++17Learn C++

How To Use The All-Powerful swscanf function In Your C++ App

C++ComponentsLanguage FeatureLearn C++

How To Use A Sharpen Effect in C+ Software On Windows?