I\'m using a DataGridView in my WinForms application. My main objective is to make the Enter key not move to the next row in the grid. I still want the enter key to validate
JJO's code will crash if cell is in edit mode. Below avoids validation exception:
DataGridViewCell currentCell = AttachedGrid.CurrentCell;
try
{
AttachedGrid.EndEdit();
AttachedGrid.CurrentCell = null;
AttachedGrid.CurrentCell = currentCell;
}
catch
{
AttachedGrid.CurrentCell = currentCell;
AttachedGrid.CurrentCell.Selected = true;
}
Source: Kennet Harris's answer here