'wxGrid, GridColLabelWindow mouse capture assertion failed

I am capturing the mouse for GridColLabelWindow but getting an assertion message "!wxMouseCapture::IsInCaptureStack(this) failed. Recapturing the mouse in the same window?" for the following code:

GetGridColLabelWindow()->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& evt) {
            //GetGridColLabelWindow()->ReleaseMouse();

            if (GetGridColLabelWindow()->HasCapture() == false)
                GetGridColLabelWindow()->CaptureMouse();

            evt.Skip();
            });

This only happens when I click on the grid label window to change the column width (does NOT happen when clicked on grid col label window to select rows).

As an experiment, if I attempt to release mouse before capturing then following assertion is issued "wxWindowBase::ReleaseMouse(): Releasing mouse in 000xxxx (wxWindow) but it is not captured".

I wonder if this is a bug or if I am missing something (wxWidgets 3.1.4, Windows 10, VS 2019).



Solution 1:[1]

In general you're not supposed to interfere with the built-in mouse handling and the grid windows have their own, relatively complicated logic, dealing with the mouse capture, so it's not really surprising that doing what you do breaks it. I'm not sure what exactly are you trying to do, but try handling wxGrid higher level events to implement it, if possible (one problem here is that the resizing events are still not generated as of 3.1.6, but it would be nice to add them...).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VZ.