Pergunta

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;
Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top