I had a dataGridView in which if I clicked a cell, it will look like this

I had to click the cell twice to get the focus.I wanted to click the dataGridViewCell and immediately get the focus. Something like this:

Clicking twice the dataGridViewCell to get the focus is annoying. This is the code that helped me to put the focus in the dataGridViewCell immediately:
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
// puts the current cell in edit mode
dataGridView1.BeginEdit(false);
}
I would also like to thank Lisurc for his input in this topic. He had another solution to it, and it works just as good what is stated above. Thanks for your contribution Lisurc.
If you have another way to solve this problem, please comment it, and let me know.
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
}
August 13th, 2007 at 1:33 pm
You also may (actually, I think you should) use the EditMode property of a DataGridView and set it to “EditOnEnter”. That should do the trick.