Look at my Unit:
unit untMainForm;
interface
uses
WinApi.Windows,
System.Classes, System.SysUtils,
Vcl.Forms, Vcl.Controls, Vcl.Grids, Vcl.DBGrids, Vcl.Graphics, Vcl.Dialogs,
Data.DB, Datasnap.DBClient, Vcl.StdCtrls;
type
TMainForm = class(TForm)
dbgLink: TDBGrid;
cdsLink: TClientDataSet;
dasLink: TDataSource;
cdsLinkID: TIntegerField;
cdsLinkLink: TStringField;
lblCoord: TLabel;
procedure FormCreate(Sender: TObject);
procedure dbgLinkMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure dbgLinkCellClick(Column: TColumn);
private
mouseCell: TGridCoord;
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
procedure TMainForm.FormCreate(Sender: TObject);
var
nI: Integer;
begin
cdsLink.CreateDataSet;
for nI := 1 to 5 do
begin
cdsLink.Append;
cdsLinkID.AsInteger := nI;
cdsLinkLink.AsString := '[email protected] ' + IntToStr(nI);
end;
cdsLink.Post;
end;
procedure TMainForm.dbgLinkMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
mouseCell := dbgLink.MouseCoord(X,Y);
if mouseCell.X = 2 then
Screen.Cursor := crHandPoint
else
Screen.Cursor := crDefault;
lblCoord.Caption := Format('Coordenadas X: %d, Y: %d', [mouseCell.X, mouseCell.Y]);
end;
procedure TMainForm.dbgLinkCellClick(Column: TColumn);
begin
if mouseCell.X = 2 then
begin
ShowMessage(Format('Coluna: %d', [mouseCell.X]));
end;
end;
initialization
ReportMemoryLeaksOnShutdown := true;
end.
source: http://drgarcia1986.wordpress.com/2013/01/17/dicas-sobre-o-componente-dbgrid-do-delphi/
The method dbgLink.MouseCoord(X,Y);
returns the cell in coordinates also according to the mouse position passed by the event OnMouseMove
.
I completely rephrased the question to make my goal clearer.
– Daniel Grillo
Would you have any problem using the event onCellClick tdbgrid?
– EMBarbosa
Dear @Danielgrillo, could post how you solved the problem? Grateful!
– user3628