Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set focus on a particular row in a datagrid/gridview?

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#?

like image 853
Sukanya Avatar asked Dec 26 '11 12:12

Sukanya


3 Answers

For WinForms DataGridView:

myDataGridView.CurrentCell = myDataGridView.Rows[theRowIndex].Cells[0];

For WebForms GridView, use the SelectedIndex property

myGridView.SelectedIndex = theRowIndex;
like image 150
akoso Avatar answered Nov 01 '22 09:11

akoso


Try this

dataGridView1.ClearSelection();
int nRowIndex = dataGridView1.Rows.Count - 1;

dataGridView1.Rows[nRowIndex].Selected = true;
dataGridView1.Rows[nRowIndex].Cells[0].Selected = true;
like image 17
Wael Dalloul Avatar answered Nov 01 '22 09:11

Wael Dalloul


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);
like image 2
Manoj Savalia Avatar answered Nov 01 '22 11:11

Manoj Savalia