您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

How to create a OnCellDblClick for Delphi's TDBGrid

bubuko 2022/1/25 20:10:11 其他 字数 3116 阅读 1013 来源 http://www.bubuko.com/infolist-5-1.html

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

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

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


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶