Post by Linda Liu[MSFT]Hi Paul,
When a DataGridView control gets focused and the user presses the ESC key,
the DataGridView exits from the edit mode if it was in edit mode and then
passes the ESC key to the form.
To get what you want, you need to prevent the ESC key from being passed to
the form in the above case.
To do this, derive a new class from the DataGridView class and override the
ProcessDialogKey method. If the current cell is in edit mode, call the
ProcessEscapeKey method to process the ESC key and return true directly;
otherwise, call the base.ProcessDialogKey method.
class MyDataGridView : DataGridView
{
protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData == Keys.Escape)
{
if (this.CurrentCell.IsInEditMode)
{
this.ProcessEscapeKey(Keys.Escape);
return true;
}
}
// If the keyData is Keys.Escape, the base.ProcessDialogKey
method will pass the ESC key to the form.
return base.ProcessDialogKey(keyData);
}
}
Use the derived DataGridView instead of the standard DataGridView on your
form.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.