So it's easy enough to check if a cell has been clicked with:
DataGridView.CellClicked += cellClickedHandler;
And it's easy enough to check if a key has been pressed with:
DataGridView.KeyDown += keyPressedHandler;
I'm wondering how I can go about combining those two functions into one? I would like to perform a specific action when a user control clicks a cell and as far as I can tell, the action handlers for these events are two unique, independent functions and the parameters passed to cellClickedHandler don't allow me to get the state of the keyboard and any key presses that may be firing in conjunction with the mouse click.
private void cellClicked(object sender, DataGridViewCellMouseEventArgs e)
{
if(e.Button == MouseButtons.Right) // right click
{
if (Control.ModifierKeys == Keys.Control)
System.Diagnostics.Debug.Print("CTRL + Right click!");
else
System.Diagnostics.Debug.Print("Right click!");
}
if (e.Button == MouseButtons.Left) // left click
{
if (Control.ModifierKeys == Keys.Control)
System.Diagnostics.Debug.Print("CTRL + Left click!");
else
System.Diagnostics.Debug.Print("Left click!");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With