I.T. Discussion Community!
-Collapse +Expand
Search Delphi Group:

-Collapse +Expand Delphi To/From
-Collapse +Expand Delphi Store

Prestwood eMagazine

February Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingDelphi for W...Using Controls   Print This     
  From the July 2008 Issue of Prestwood eMag
Delphi Using Controls:
TStringGrid Example
Posted 11 years ago on 2/26/2008
Take Away: To determine the total number of columns in a String Grid, refer to its ColCount property and for the total number of rows, refer to RowCount. Determing the currently selected cell is a simple matter of referring to the Col and Row properties.


According to the Delphi help, a String Grid (TStringGrid) is "a grid control designed to simplify the handling of strings and associated objects."

The String Grid has a layout that is very similar to a spreadsheet, with columns and rows. To reference a particular cell, you specify its column and row numbers. For example, if you want to work with the contents of the cell located 3 cells over and 2 cells down, use the following code:


To determine the total number of columns in a String Grid, refer to its ColCount property and for the total number of rows, refer to RowCount.

Determing the currently selected cell is a simple matter of referring to the Col and Row properties.

You can step through each cell's contents by creating two loops. The first thing you need to determine is which direction you want to examine the cells. You can either travel across each row, like records in a table, or you can travel down each column. If you want to examine the cells like a record, the first, or outer, loop would travel the rows and the second, or inner, loop would travel the columns.
By default, the String Grid ignores the ENTER and TAB keys. If you want to include functionality based on those keys it is necessary to trap them with the Key events. A simple example of trapping keys is also included in the sidebar example, it converts all keypresses to uppercase before applying it to the cell.
Create a new application by clicking File|New in Delphi. When the form has been created, drop a String Grid and a Button onto it. Set the String Grid's Options|goEditing property to True. Finally, enter the following code:

procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char); 
   Key := UpCase(Key);
procedure TForm1.Button1Click(Sender: TObject); 
   ColCounter,   RowCounter  : Byte;
   CellStr     : String;
   with StringGrid1 do
     for RowCounter := 1 to RowCount do
       for ColCounter := 1 to ColCount do
         CellStr := StringGrid1.Cells[RowCounter, ColCounter];
          if CellStr <> '' then
           ShowMessage('Cell[' + IntToStr(ColCounter) + ':' + IntToStr(RowCounter) + '] = ' + CellStr);


Share a thought or comment...
Comment 1 of 2


My name is Henryk

Living in Poznan in Poland

I am looking for solution and ... there's problem to describe that all using my "poor" english

but let me try at last :)

There is a turnamen of chess with x- palyers I can create: table, pairs for each round and so one and so one. My problem is there as I mentoned x - players each of them has own Card of Player After each round winers, losers or draws makers has note in own card to get total result after turnament and to iknow raking up or down ...Big Grin!But how to save after a round result and to know what info belong to a player ?:( sumary it's for 13 round max turnament I wouldn't like to create DataBase file but something like Records of *.dat file Shall I create 13 files for each round? or enough to create one file ?

If tere is any sugestion Please drop me it on my mail address below:


Thans !!!

Posted 7 years ago

Comment 2 of 2

PS: I forgot to add : Info in Card of a player has also names of oponetnts , results of other games and raking of oponents ... Hope I describe all it as should be done :)

Posted 7 years ago
Write a Comment...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.

Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1182A1
Enter key:
KB Post Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #100886 Counter
Since 4/2/2008
   Contact Us!
PrestwoodBoards.com was developed and is maintainted by me. Do you have a question or suggestion? Do you see a problem? Contact me now. My goal is to build an ad-free and spam-free source of I.T. information with many contributers (ok to promote your website/company in your bio). Yes, my company Prestwood IT Solutions is mentioned in my bio which shows with every post, but you can contribute and promote your pet project too!

2,080 People Online Now!!  
Sign In to see who's online now!  Not a member? Join now. It's free!
Show more stats...

©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech