Delete Key in DataGrid

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

Guest

Hello All,

I Need to disable delete key so it should not delete rows from the datagrid
but should be able to use the delete key when editing the cell. If any one
has any suggestions please let me know.

Thanks
Raj
 
This Windows Forms FAQ entry shows how you can put up a confirmation
question before deleting the row. You can do the same thing but just not
display the question to ignore the delete key.

George Shepherd's Windows Forms FAQ contains an entry entitled:

How can I put up a confirmation question when the user tries to delete
a row in the datagrid by clicking on the row header and pressing the Delete
key?

Check it out at:
http://www.syncfusion.com/faq/winforms/search/889.asp

=============================================
Clay Burch, .NET MVP

Syncfusion, Inc.
visit http://www.syncfusion.com for .NET Essentials
 
The solution in the FAQ will not handle this problem.

But here is an derived datagrid using a ProcessCmdKey override. It allows
the delete key to work when editing a cell but ignores it if you try to use
it to delete a row.


public class MyDataGrid : DataGrid
{
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
Keys keyCode = (Keys)(int)msg.WParam & Keys.KeyCode;
if(msg.Msg == 256
&& keyCode == Keys.Delete
&& this.IsSelected(this.CurrentRowIndex)
)
{
//if(MessageBox.Show("Delete this row?", "", MessageBoxButtons.YesNo) ==
DialogResult.No)
return true;
}
return base.ProcessCmdKey (ref msg, keyData);
}
}


=======================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
Back
Top