Solved

TDBGrid

Posted on 1998-02-02
1
396 Views
Last Modified: 2010-05-18
hi
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)

10x
asi
0
Comment
Question by:asi
1 Comment
 
LVL 8

Accepted Solution

by:
ZifNab earned 50 total points
ID: 1358130
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;

                   interface

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

                   type
                     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
                       { Private declarations }

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

                   var
                     Form1: TForm1;

                   implementation

                   {$R *.DFM}

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

                   procedure TForm1.DBGrid1ColEnter(Sender: TObject);
                   begin
                     ShowRowCol;
                   end;

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

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

                   end.

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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now