IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

October 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 16 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.

KB100886


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:

StringGrid1.Cells[3,2]

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

Comments

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

Hi,

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:

kallas55555@wp.pl

Thans !!!

---
Henryk
Posted 12 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 :)

---
Hneryk
Posted 12 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 = P157A1
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
25460
Since 4/2/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]