Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you disable a DataGridView's keyboard shorcuts?

I've just noticed that DataGridViews have a default shortcut so that whenever you press Ctrl + H, the DataGridView's editing control backspaces, and can delete your entire selection within the cell.

This can get quite annoying since I want to open a Replace box whenever Ctrl + H is pressed. Is there any way to stop the backspacing while still being able to use it to open the replace box?

I'm running C# 2.0, but I could update my application to 3.5 if the newer C# has a solution.

like image 435
User2400 Avatar asked Apr 12 '10 02:04

User2400


1 Answers

This goes into your form code:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{     
  if (keyData == (Keys.Control | Keys.H))
  {
    //ShowReplaceDialog() or whatever it is you want to do here.
    return true; //we handled the key
  }

  return base.ProcessCmdKey(ref msg, keyData); //we didn't handle it
}
like image 108
szevvy Avatar answered Sep 23 '22 17:09

szevvy