Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Thread Tools Display Modes
Old 06-23-2006, 10:35 AM
greener greener is offline
Join Date: Oct 2004
Posts: 79
Default capture cell content from dbGrid with mouse click event

Hi Guys,
I am trying to see if anyone has an example how to capture a
content of the single cell from a datagrid with the mouse click and store into the variable.


Reply With Quote
Old 06-23-2006, 11:18 AM
Lalavava Lalavava is offline
Senior Member
Join Date: Oct 2002
Posts: 235
Default RE: capture cell content from dbGrid with mouse click event

maybe this can ba a way to start:

Retrieve cell values of a TDBGrid using MouseCoord

THackDbGrid = class(TDBGrid);

procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
gc: TGridCoord;
dbg: TDBGrid;
SavedActiveRec: integer;
dbg := TDBGrid(Sender);
gc := dbg.MouseCoord(X, Y);
if (gc.X > 0) and (gc.X < dbg.Columns.Count) and (gc.Y > 0) then
SavedActiveRec := THackDbGrid(Dbg).DataLink.ActiveRecord;
THackDbGrid(Dbg).DataLink.ActiveRecord := gc.Y - 1;
Dbg.Hint := dbg.Columns[gc.X - 1].Field.AsString;
THackDbGrid(Dbg).DataLink.ActiveRecord := SavedActiveRec;
Dbg.Hint := '';

Please click accept if this helps
Reply With Quote
Old 06-23-2006, 02:25 PM
Jasser Jasser is offline
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,060
Default RE: capture cell content from dbGrid with mouse click event

Use "OnCellClick" event of the DBGrid. Example:

[DELPHI]procedure TForm1.DBGrid1CellClick(Column: TColumn);
Showmessage( Column.Field.Value );

Abdulaziz Jasser
Reply With Quote
Old 04-30-2016, 07:55 AM
jerbear jerbear is offline
Junior Member
Join Date: Jun 2009
Location: Ireland
Posts: 17
Send a message via Skype™ to jerbear

Looking for an answer to this myself.

This only half worked...
Showmessage( Column.Field.Value ); ( Modified to Showmessage( Column.Field.AsString); because I want all values displayed as strings.)

It only displays the contents of the selected cell in Column zero No matter where on the grid I click.

Right Field, Right Row, but always column zero.... WHY? Please???????

Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 09:30 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.