views:

163

answers:

3

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.

+4  A: 

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 false; //we didn't handle it
}
szevvy
Thanks it works perfectly! Can you give me any pointers on when to override ProcessCmdKey instead of just handling a KeyDown event?
fneep
Not sure, TBH.MSDN says:"This method is called during message preprocessing to handle command keys. Command keys are keys that always take precedence over regular input keys. Examples of command keys include accelerators and menu shortcuts."
szevvy
A: 
yona
A: 

How to move to next cell in datagridview when the user clicks enter and atlast it has to move to next row.

And How to add two column and display in third column when a user press or moves to fourth column in datagridview in C# windows application.

Kavitha Kala Hari Haran