private void frmSearch_KeyDown(object sender,System.Windows.Forms.KeyEventArgs e) { switch (e.KeyCode) { case Keys.Escape : this.Close(); e.Handled=true; break; case Keys.F5 : this.Search(); e.Handled=true; break; } }I read thread #1053288 , where Bonnie Berent gives the code to trap for keys, so I created a DataGrid subclass with the following:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { const int WM_KEYDOWN = 0x100; const int WM_SYSKEYDOWN = 0x104; if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN)) { switch(keyData) { case Keys.F5 : this.EndEdit(); MessageBox.Show("F5"); break; } //switch } //if return base.ProcessCmdKey(ref msg,keyData); }The messagebox pops open.