Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to discard mouse click in TDbGrid.OnColumnMoved

In a TDbGrid.OnColumnMoved event handler, I adjust some column headings colors.

I also use the grid's OnTitleClicked event to pop-up a (sort column) menu.

Unfortunately, after the user drags a column and OnColumnMoved is finished, the VCL calls OnTitleClicked. This means my sort-order pop-up appears after column dragging.

Is there a way in OnColumnMoved I can clear the mouse event queue so that OnTitleClicked doesn't get called?

This thread has this code, but I don't have a Msg in OnTitleClicked.

while PeekMessage(Msg, 0, WM_MOUSEFIRST, WM_MOUSELAST, 
  PM_REMOVE or PM_NOYIELD) do;

(If there's no way to do this, it's not big deal. I can set a flag in OnColumnMoved so that OnTitleClick ignores the next call to it.)

like image 551
RobertFrank Avatar asked Dec 14 '11 02:12

RobertFrank


1 Answers

As mentioned in comments to the question, you would supply the 'Msg' for PeekMessage yourself (var Msg: TMsg). But discarding the message that triggers OnTitleClickis not possible because it is the same message that fires both events. VCL carries out column moving in response to a WM_LBUTTONUP message if a column has been dragged. Later during the handling of the same message OnTitleClick is called.

IOW, while you can remove messages from the message queue with PeekMessage, the message that triggers OnTitleClick is already dispatched since we are in an OnColumnMoved handler.

Easiest approach looks like setting the flag as you've told.

like image 137
Sertac Akyuz Avatar answered Oct 12 '22 14:10

Sertac Akyuz