break

DataGridView CellEnter event

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

before cell enter

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:

after cell enter

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;
}

One Response

  1. Lisurc Says:

    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.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

CAPTCHA Image
Reload Image