How to force datagridviewcell to end edit when row header is clicked
i ran into exactly the same problem this week! it appears this is a pretty well documented bug in the datagridview. i'm unsure if it's been fixed in any later versions. checking for a row header when the grid is clicked and changing the editmode seems to work though:
private void dataGridView_MouseClick( object sender, MouseEventArgs e ) {
DataGridView dgv = (DataGridView)sender;
if (dgv.HitTest(e.X, e.Y).Type == DataGridViewHitTestType.RowHeader) {
dgv.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
dgv.EndEdit();
} else {
dgv.EditMode = DataGridViewEditMode.EditOnEnter;
}
}
however this is still an irritating work around if you use many datagridviews throughout your application, so let me know if you discover a better solution.
EDIT: this question seems to have a similar solution