Tim Van Wassenhove

Passionate geek, interested in Technology. Proud father of two

16 Sep 2006

DataGridView with EditOnEnter as EditMode

Earlier this week i found that when a DataGridView has it’s EditMode property set to EditOnEnter the user cannot select an entire row by clicking on the row header. This prevents the user from being able to delete a row. A couple of websearches later i found a bugreport but the proposed workarounds didn’t work for me 🙁 Here is a workaround that does work for me

private void dataGridView1_MouseClick( object sender, MouseEventArgs e ) 
{
	DataGridView.HitTestInfo hitInfo = this.dataGridView1.HitTest(e.X, e.Y);
	if( hitInfo.Type == DataGridViewHitTestType.RowHeader ) 
	{
		this.dataGridView1.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
		this.dataGridView1.EndEdit();
	}
	else
	{
		this.dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
	}
}