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.

close

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.

About author

Dr. Yilmaz Yoru has 33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He was born in 1974, Eskisehir-Turkey, started coding in college and graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. He worked as a research assistant at the same university for more than 10 years. He received his MSc and PhD degrees from the same department at the same university. Since 2012, he is the founder and CEO of Esenja LLC Company. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17Generic ProgrammingLearn C++Templates

What Is A Template In C++?

C++C++17Code SnippetComponentsIteratorsLearn C++

What Are The Boost C++ Libraries?

C++C++17Introduction to C++Learn C++Syntax

Learn Bits and How To Use std::bitset In C++

C++C++17IteratorsLearn C++

How To Use Insert In std::map In Modern C++