Hi Srikanth,
Based on my understanding, you want to intercept the "Delete" key down
event in DataGrid.
Yes, most of the time, DataGrid's KeyDown event will work well, but if we
press key in DataGridTextBoxColumn, this event handler will not fire when
pressing. This is because, in edit mode, there is actually a TextBox in
that column, and this textbox has the focus, so only the TextBox's keydown
event will fire.
For your requirement, we have 2 options:
1. If you just want to be notified when user press "Delete" key, we may
hook both DataGridTextBoxColumn and the DataGrid's keydown event. We should
explicitly add a DataGridTextBoxColumn into the datagrid, then get the
reference of TextBox in that column and hook its KeyDown event, like this:
private void Form1_Load(object sender, System.EventArgs e)
{
DataGridTextBoxColumn dgtbc=new DataGridTextBoxColumn();
dgtbc.MappingName="binding column name";
dgtbc.TextBox.KeyDown+=new KeyEventHandler(TextBox_KeyDown);
DataGridTableStyle dgts=new DataGridTableStyle();
dgts.GridColumnStyles.Add(dgtbc);
dgts.MappingName="datasource's mapping name";
this.dataGrid1.TableStyles.Clear();
this.dataGrid1.TableStyles.Add(dgts);
}
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode==Keys.Delete)
{
MessageBox.Show("TextBox_KeyDown");
}
}
private void InitializeComponent()
{
this.dataGrid1.KeyDown += new
System.Windows.Forms.KeyEventHandler(this.dataGrid1_KeyDown);
}
private void dataGrid1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode==Keys.Delete)
{
MessageBox.Show("dataGrid1_KeyDown");
}
}
2. If you not only want to be notified, but also want to do something to
this keyevent(such as disable the delete keydown operation), we may inherit
from normal DataGrid class, and override its ProcessCmdKey method, and
intercept the "delete" keydown return "true" to indicate this event has
been handled(so the following operation won't take place, that is the
delete function is disabled!), sample code like this:
const int WM_KEYDOWN=0x100;
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(msg.Msg==WM_KEYDOWN)
{
if(keyData==Keys.Delete)
{
MessageBox.Show("Delete");
return true; //disable the following delete function
}
}
return base.ProcessCmdKey (ref msg, keyData);
}
This both works well on my side.
For more information about FAQ about Winform datagrid, please refer to:
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
You will find many useful information here.
===================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.