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.)
As mentioned in comments to the question, you would supply the ‘Msg’ for
PeekMessageyourself (var Msg: TMsg). But discarding the message that triggersOnTitleClickis not possible because it is the same message that fires both events. VCL carries out column moving in response to aWM_LBUTTONUPmessage if a column has been dragged. Later during the handling of the same messageOnTitleClickis called.IOW, while you can remove messages from the message queue with
PeekMessage, the message that triggersOnTitleClickis already dispatched since we are in anOnColumnMovedhandler.Easiest approach looks like setting the flag as you’ve told.