how to capture the event that someone press a 'del' key when highlight a row in a datagrid?

  • Thread starter Thread starter ywchan
  • Start date Start date
Y

ywchan

I would like to have a datagrid that can be edited but not delete...
and I have no idea how to capture the del key press event.
Please help, thank!
 
Hi YWChan,

one was to do this is to use the DataGrid as a subclass 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 answers your question to some level.

Mark.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top