Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

TDBGrid

Posted on 1998-02-02
1
Medium Priority
?
404 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
ZifNab earned 100 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

660 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