Recent

Author Topic: [SOLVED] DBGrid -DblClick fires CellClick too  (Read 3921 times)

wittbo

  • Full Member
  • ***
  • Posts: 150
[SOLVED] DBGrid -DblClick fires CellClick too
« on: March 01, 2017, 12:28:58 am »
I'm working with Lazarus 1.4.4. on macOS 10.10.5.

My application makes intensive use of DBGrids. Actually I found, that, when I double-click a cell/row, not only the OnDBlClick event is fired, but more than that, first a CellClick followed by a DblClick and then followed again by a CellClick event is fired. Since I have different handlers on CellClick and DblClick, this is very annoying.
Any idea?

-wittbo-
.
« Last Edit: March 02, 2017, 01:26:44 pm by wittbo »
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: DBGrid -DblClick fires CellClick too
« Reply #1 on: March 01, 2017, 12:53:02 am »
The same in Delphi Berlin, by the way...

In order to distinguish between conflicting single and double-clicks you can use a timer. Enable the timer in the MouseDown event. Set its duration a bit longer than the standard double-dlick time. In the OnTimer event of the timer, disable the timer again and process the code that you would have in the OnClick event. The old OnClick event is not needed any more.

I should not conceal the disadvantage: the application will feel a bit sluggish because the OnClick reaction is delayed by the duration of the timer.

Best would be to avoid such conflicting situations in the user interface.

wittbo

  • Full Member
  • ***
  • Posts: 150
Re: DBGrid -DblClick fires CellClick too
« Reply #2 on: March 01, 2017, 07:03:52 am »
The real problem was the CellClick after the preceding DblClick event. I solved it this way: in the DblClick handler I added a flag to remember this DblClick event. The first action in the CellClick event is to look at this flag. If the flag is set, then do nothing but to reset the flag, otherwise do normal handler action.
-wittbo-
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

 

TinyPortal © 2005-2018