Skip to main content Skip to footer

How to distinguish between CellClick and CellDoubleClick events in WinForms

Issue:

Spread exposes two cell click events: CellClick and CellDoubleClick. When both these events are handled CellClick event fires with both, single cell click and double cell click. This is problematic in situations where these events are expected to perform different actions.

For instance, assume there are two actions A and B where action A needs to be performed only on single cell click and action B on double cell click. With the current behavior, if the cell is single clicked, only the CellClick event will fire and only action A will perform (expected). Although, if the cell is double clicked, first CellClick fires followed by CellDoubleClick, therefore first action A will perform followed by action B (not expected)(expected was to only perform action B)

Therefore, this article shows how to distinguish between CellClick and CellDoubleClick events in Spread for WinForms.

Resolution:

This behavior is by-design since the CellClick event is raised when the mouse is up from the first click and it does not wait to check if the mouse is pressed again. Hence it fires with both, single cell click and double cell click.

To distinguish, following workaround can be used:

private void FpSpread1_CellClick(object sender, CellClickEventArgs e)
{
    _timer.Stop();

    _timer.Tag = e;
    _timer.Start();
}
private void FpSpread1_CellDoubleClick(object sender, CellClickEventArgs e)
{
    _timer.Stop();
    PerformDoubleClickAction(e);
}
private void _timer_Tick(object sender, EventArgs e)
{
    _timer.Stop();
    CellClickEventArgs cellClickEventArgs = (CellClickEventArgs)_timer.Tag;
    PerformSingleClickAction(e);
}

Tags:

Ruchir Agarwal