I have a datagrid/gridview. I'm populating the grid with 10 rows initially. On a button click every time,I'm keeping on adding 10 rows to the datagrid/gridview. Now I want to set the focus to the last row every time the grid is populated. I can get the index of that row,but I can't set focus to that particular row.
Do anyone of you have any idea how to do it in C#?
For WinForms DataGridView:
myDataGridView.CurrentCell = myDataGridView.Rows[theRowIndex].Cells[0];
For WebForms GridView, use the SelectedIndex property
myGridView.SelectedIndex = theRowIndex;
Try this
dataGridView1.ClearSelection();
int nRowIndex = dataGridView1.Rows.Count - 1;
dataGridView1.Rows[nRowIndex].Selected = true;
dataGridView1.Rows[nRowIndex].Cells[0].Selected = true;
Try this...
DataGridViewRow rowToSelect = this.dgvJobList.CurrentRow;
rowToSelect.Selected = true;
rowToSelect.Cells[0].Selected = true;
this.dgvJobList.CurrentCell = rowToSelect.Cells[0];
this.dgvJobList.BeginEdit(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With