I have written this answer thinking that you meant DataGridView
; but this code might also be useful for RadGridView
. What I usually do in these cases (with DataGridView
) is relying on a global flag to coordinate two different events; just a few global flags should be OK. Sample code:
bool aCellWasSelected = false;
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
aCellWasSelected = true;
}
private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
{
DataGridViewCell selectedCell = null;
if (aCellWasSelected)
{
selectedCell = dataGridView1.SelectedCells[0];
MouseButtons curButton = e.Button;
//Do stuff with the given cell + button
}
aCellWasSelected = false;
}
NOTE: the proposed global-variable-based approach is NOT the ideal proceeding, but a practical solution pretty handy in quite a few DataGridView-related situations. If there is a direct solution, as in this case (as proposed in the other answer or, in DataGridView, the CellMouseClick
event), you shouldn't ever use such an approach. I will let this answer as a reference anyway (for people looking for equivalent two-event-coordination situations, where no direct solution is present).