How can I change what happens when the enter key is pressed on a DataGridView?

when I edit the cell and press the enter button, the next line is automatically selected, I want to stay with the current line ... I want to do nothing but EndEdit.

I have it:

private void dtgProductos_CellEndEdit(object sender, DataGridViewCellEventArgs e) { dtgProductos[e.ColumnIndex, e.RowIndex].Selected = true; //this line is not working var index = dtgProductos.SelectedRows[0].Cells.IndexOf(dtgProductos.SelectedRows[0].Cells[e.ColumnIndex]); switch (index) { case 2: { dtgProductos.SelectedRows[0].Cells[4].Selected = true; dtgProductos.BeginEdit(true); } break; case 4: { dtgProductos.SelectedRows[0].Cells[5].Selected = true; dtgProductos.BeginEdit(true); } break; case 5: { btnAddProduct.Focus(); } break; default: break; } } 

so when I edit a line that is not the last, I get this error:

 Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function. 
+1
c # winforms
source share
1 answer

I think you need to override ProcessEnterKey so as not to skip to the next line.

Perhaps this thread will help.

+2
source share

All Articles