码迷,mamicode.com
首页 > 数据库 > 详细

How to create a OnCellDblClick for Delphi's TDBGrid

时间:2020-02-26 01:52:35      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:events   int   record   col   RoCE   index   eth   situation   mouse   

I‘m a newbie when it comes to creating new events to components... and I noticed that TDBGrid has a OnCellClick, but sadly it doesnt have an OnCellDblClick event and it bothers me a lot the fact that if I double click anywhere in my grid the selected row will be used...

So, I wanted to create the OnCellDblClick event, but as I‘ve said earlier, I don‘t know how to do it.

I noticed that a lot of people want this same event, but I can‘t find the answerd to it.

Is it possible to know if the double click was on a record, if it was, then do all the stuff I want with it?

 

Maybe you can use the DblClick together with the MouseDown event of the DBGrid
But this will only work if the Options.dgRowSelect is false

for example

type
  TForm1 = class(TForm)
  private
    FEmptySpace : boolean;
 ...

procedure TForm1.DBGrid1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  // in my test I only get here when clicked on empty part of the dbgrid
  FEmptySpace := TRUE;
end;

procedure TForm1.DBGrid1DblClick(Sender: TObject);
begin
  if FEmptySpace then
    showmessage(clicked in the middle of nowhere...)
  else
    showmessage(DBGrid1.Fields[DBGrid1.SelectedField.Index].AsString);

  FEmptySpace := FALSE;
end;

I have not tested this in all situations

In my test

  • Options.Editing := false
  • Options.dgRowSelect := false
  • Readonly := true

How to create a OnCellDblClick for Delphi's TDBGrid

标签:events   int   record   col   RoCE   index   eth   situation   mouse   

原文地址:https://www.cnblogs.com/jijm123/p/12364814.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!