Send a 'TAB' when pressing the 'Enter' key DataGridViewCellEndEdit, C #

0

I'm trying to edit the value of a Celda of DataGridView after the event CellEndEdit by pressing the% key Enter send by code a TAB I'm currently using the Event KeyPress and the EditingControlShowing of the Datagridview but it has not worked.

EditingControlShowing:

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
       TextBox textbox = e.Control as TextBox;
       if (textbox != null)
       {
             textbox.KeyPress -= new KeyPressEventHandler(dataGridView1_KeyPress);
             textbox.KeyPress += new KeyPressEventHandler(dataGridView1_KeyPress);
        }
}

KeyPress Event:

private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char)13) // Si es un enter
    {
        e.Handled = true; //Interceptamos la pulsación
        SendKeys.Send("{TAB}"); //Pulsamos la tecla Tabulador por código
    }
}

I've also tried the KeyDown Event:

if (e.KeyCode.Equals(Keys.Enter))
    SendKeys.Send("{TAB}");
  

It does not work! Any ideas on how to achieve it?

I found this answer from OS , but it does not work correctly.

Environment: Visual Studio 2010 & .NET Netframework 4

    
asked by J. Rodríguez 10.01.2018 в 21:02
source

1 answer

0

You've tried with:

<!-- language: c# -->
private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
   if (e.KeyChar == Keys.Enter) // Si es un enter
   {
      e.KeyChar = Keys.Tab;
   }
}  
    
answered by 01.03.2018 в 16:26