Set focus on a DataGridView cell
This code sample will set the editing cursor right in the first cell of the current row in DataGridView. The cell will be ready to get its new data.C#
DataGridViewRow rowToSelect = this.dgvJobList.CurrentRow;
rowToSelect.Selected = true;
rowToSelect.Cells[0].Selected = true;
this.dgvJobList.CurrentCell = rowToSelect.Cells[0];
Auto select the DataGridView cell content
If the focused cell already contains some data an you want to auto select the cell's content right after got the focus, you have to add the "BeginEdit" line, like below:C#
DataGridViewRow rowToSelect = this.dgvJobList.CurrentRow;
rowToSelect.Selected = true;
rowToSelect.Cells[0].Selected = true;
this.dgvJobList.CurrentCell = rowToSelect.Cells[0];
this.dgvJobList.BeginEdit(true);
6 comments:
Hi thanks for the code snippet it helped me and save my time
hi when i am try this code it shows the messge "Current cell can not invisible" pls send the reply ASAP.
Thx, gave me a nice pointer at what to try.
awsome dude!!
i was able to setfocus, but not able to start editing by default. I had to again click on the cell to start editing.
this is cool.
God bless you.
thanks for this ...
tnx it such a big help :)
Post a Comment