* * *

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

wittbo

  • New member
  • *
  • Posts: 16
[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-
Lazarus 1.4.4  with FPC 3.0.0

wp

  • Hero Member
  • *****
  • Posts: 3353
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.
Lazarus trunk / fpc 3.0.0 / Win32

wittbo

  • New member
  • *
  • Posts: 16
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-
Lazarus 1.4.4  with FPC 3.0.0

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus