I would expect what you did to work. But a DataGridView is a complex control with many events, and often it does not work intuitively. It appears that when the EditingControlShowing event EditingControlShowing , the control is not yet initialized, so you cannot affect it. And when the CellBeginEdit event CellBeginEdit , the control has not yet been created.
There should be and probably the best way to do this, but I got it to work using the CellEnter event:
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e) { if (dgv.CurrentCell.EditType == typeof(DataGridViewTextBoxEditingControl)) { dgv.BeginEdit(false); ((TextBox)dgv.EditingControl).SelectionStart = 0; } }
So, when the cell is entered, I just go directly to edit mode, but pass false to BeginEdit() , which tells it not to select any text. Now the edit control is fully initialized, and I can set SelectionStart to zero to move the cursor to the beginning of the text.
If the cell is not a text field, I do nothing.
If you want, you can do
dgv.EditMode = DataGridViewEditMode.EditProgrammatically;
so that you have full control over the start of editing, but I believe that this is not necessary.
source share