How to cancel a mouse click in TDbGrid.OnColumnMoved

In the event handler, TDbGrid.OnColumnMovedI adjust the colors of the column headers.

I also use the grid event OnTitleClickedfor the popup menu (sort column).

Unfortunately, after the user drags the column and is OnColumnMovedfinished, VCL calls OnTitleClicked. This means that the sort-order popup appears after you drag the column.

Is there a way in OnColumnMovedI can clear the mouse event queue so that it is OnTitleClickednot called?

This thread has this code, but I don't have one Msgin OnTitleClicked.

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

(If there is no way to do this, this does not really matter. I can set the flag OnColumnMovedto OnTitleClickignore the next call.)

+5
source share
1 answer

As mentioned in the comments on the question, you yourself would put "Msg" for PeekMessage( var Msg: TMsg). But discarding a message that fires OnTitleClickis not possible, because it is the same message that fires both events. VCL moves a column in response to a message WM_LBUTTONUPif the column is dragged. Later during processing the same message is called OnTitleClick.

IOW, while you can delete messages from the message queue with PeekMessage, the message that starts OnTitleClickis already sent because we are in the handler OnColumnMoved.

The simplest approach looks like setting a flag, as you said.

+5

All Articles