Solved

TDBGrid

Posted on 1998-02-02
1
399 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 67
indy Tmemory stream non latin charcter issue 2 121
delphi parse string to params 3 136
select query - oracle 16 100
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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