I am using DevExpress grid control (C#/.NET WinForms) and handling the double-click event.

By default the grid fires the event when double clicking on the grid header as well as the data row.

The double click handler only passes EventArgs so there is no mouse position info to use to calculate the hit info of where the user was clicking in the grid.

In order to get round this I am querying the Control.MousePosition value, converting it to grid coords and then calculating the hit info.

This all appears to work fine, but is there any danger in querying the MousePosition like this during an event handler?

Example code inside event handler

        // if the double click was fired outside a row then ignore it
        GridHitInfo gridHitInfo = GridView.CalcHitInfo(Grid.PointToClient(MousePosition));
        if (!gridHitInfo.InRow)
            return;
有帮助吗?

解决方案

Yes, this works fine. Any updates to MousePosition happen synchronously (i.e. they don't change during the invocation of your handler).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top