[SOLVED] DataGridView KeyDown does not fire when cell is in editmode

Answered
0
0

Hi,

I need to detect KeyDown when the cell is in editmode. How can i accomplish that?

The KeyDown event on the grid does not fire when a cell is in editmode.

Thanks.

Best regards,

Wilfred

  • You must to post comments
Best Answer
0
0

Another option is to use the DataGridView’s EditingControlShowing event.

Something like this:

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
 {
 e.Control.KeyDown -= myKeyDownEvent;
 e.Control.KeyDown += myKeyDownEvent;
 }

Best,

Levie

  • Wilfred Schønegge
    Thanks again. Even simpler solution. I think I will use this one.
  • You must to post comments
Best Answer
0
0

Hi Wilfred,

There is a pretty easy way to get around this.

  1. Create a TextBox (or other control)
  2. Assign your DataGridView Column editor to this TextBox, i.e., this.dataGridView1.Columns[0].Editor = this.textBox1;
  3. Attach a KeyDown event handler to the TextBox.

Let me know if this works for you!

Best regards,

Levie

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.