Cannor capture DEL key in DataGrid event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to capture when the user clicks the DEL key on the keyboard for
me to grab the row index on a datagrid. I am running out of ways to do this.I
have tried ...

private void dataGrid1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
MessageBox.Show("I am here");
}

And its not showing me the message box that i was expecting. I have also
tried _KeyUP and _KeyPress to no avail.

Any suggestions?
 
Hi Zest4Csharp,

you could use the DataGrid as a baseclass, inherit from it and then override
the ProcessCmdKey method, for example:

class MyDataGrid : DataGrid
{
public MyDataGrid() : base()
{
}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(keyData == Keys.Delete)
{
//do processing for delete

//return true to stop the event being raised and deleting
return true;
}

return base.ProcessCmdKey(ref msg, keyData);
}
}



Hope that helps
Mark R Dawson
 
I have read this reply and would like to understand it better. Could one of
you please reply with an explaination of how to best use this code?

Thanks in advance
 
Back
Top