Friends again I come for help.
I commented that I am working on a Form
that contains a DataGridView
in which I must control a data entry sequence to said DataGridView
, but I need to follow the sequence from left to right, now my problem , if I press "Enter" the active cell changes to the one below and this is not what I need. What I need is that when I finish editing the cell with a Tab
or a Enter
go to the next column
Any suggestions on how I could control that? Thank you very much
So far I have tried two ways that I found on the Internet
1.- The first one, a bit basic but it does not work for me, in the KeyDown event of the DataGridView
private void dtVentas_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.Handled = true;
SendKeys.Send("{TAB}");
MessageBox.Show("Deberia pasar a la siguiete celda");
}
2.- The second one is: With the EditingControlShowing method of the DataGridView and in this event I call the KeyPress event of the same table and in the latter I validate the key that I press but it does not work either. Data Apart, in this same method I perform the validations of what kind of data I can enter in the cell of the table, I do not know if that is relevant.
Code:
private void dtVentas_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
DataGridViewTextBoxEditingControl dText = (DataGridViewTextBoxEditingControl)e.Control;
dText.KeyPress -= new KeyPressEventHandler(dtVentas_KeyPress);
dText.KeyPress += new KeyPressEventHandler(dtVentas_KeyPress);
}
KeyPress Event:
private void dtVentas_KeyPress(object sender, KeyPressEventArgs e)
{
//
switch (this.dtVentas.CurrentCell.ColumnIndex)
{
case 0:// CASO 0 PARA EL CODIGO DEL ITEM
//MessageBox.Show("Llegue al evento keypress");
if (e.KeyChar == (char)Keys.Enter)
{
MessageBox.Show("Di un enter en la tabla");
SendKeys.Send("{UP}");
SendKeys.Send("{TAB}");
}
else
{
this.dtVentas.Rows[this.dtVentas.CurrentRow.Index].ErrorText = "Solo Numeros en la Columna 'Codigo Item'";
e.Handled = Obj.SoloNumeros(e);
}
break;
}
}