• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 408
  • Last Modified:


i"m using the TdbGrid ...
is there is any way to know the cell cordinat that i"m standgin on ... because i want to put on this cell cordinat my own Tcontrol (to enter data), and  how i know when the user make scroll action (so i'll know the new cell cordinate)

1 Solution
Hi asi,

to know the cell co├Ârdinats :

do you just want to select the cell? Here is an example :
                   (Look at the header of the form. Think the way of getting the row and col selected is
                   interesting) If I'm wrong, please specify the problem.

                   try it this way:

                   unit unit1;


                     SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
                     Forms, Dialogs, DB, DBTables, Grids, DBGrids;

                     TForm1 = class(TForm)
                       DBGrid1: TDBGrid;
                       DataSource1: TDataSource;
                       Table1: TTable;
                       procedure DBGrid1ColEnter(Sender: TObject);
                       procedure DataSource1DataChange(Sender: TObject; Field: TField);
                       procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
                       Field: TField; State: TGridDrawState);
                       { Private declarations }

                       { Public declarations }
                       procedure ShowRowCol;
                     THack = class(TDBGrid);

                     Form1: TForm1;


                   {$R *.DFM}

                   procedure TForm1.ShowRowCol;
                     caption := 'Row: ' + IntToStr(THack(DBGrid1).row) + ' ' + 'Col: ' +

                   procedure TForm1.DBGrid1ColEnter(Sender: TObject);

                   procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
                     if (Sender as TDataSource).State = dsBrowse then ShowRowCol;

                   Procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
                     Field: TField; State: TGridDrawState);
                      If gdFocused in State then
                       with (Sender as TDBGrid).Canvas do begin
                       Brush.Color := clRed;
                       TextOut(Rect.Left, Rect.Top, Field.AsString);


When a user moves the scrollbar, it doesn't says that the active cell changes : so you need to find the movement event another way. Like pushing the enter or tab, or arrow keys.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now