Delphi Pages Forums  

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

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 06-23-2006, 10:35 AM
greener greener is offline
Member
 
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.

thanks,

Chris
Reply With Quote
  #2  
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

type
THackDbGrid = class(TDBGrid);

procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
gc: TGridCoord;
dbg: TDBGrid;
SavedActiveRec: integer;
begin
dbg := TDBGrid(Sender);
gc := dbg.MouseCoord(X, Y);
if (gc.X > 0) and (gc.X < dbg.Columns.Count) and (gc.Y > 0) then
begin
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;
end
else
Dbg.Hint := '';
end;


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

Use "OnCellClick" event of the DBGrid. Example:


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

Regards,
Abdulaziz Jasser
Reply With Quote
  #4  
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
Default

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???????

Jerbear
Reply With Quote
Reply

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 12:30 AM.


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