Friday 24 October 2008

Programmatically select DataGridView row

This can be useful if we are updating a row in a DataGridView and we want to refresh the DataSource, still the selected row to remain the same.


   1:  if (selectedIndex > -1 && dataGridView1.Rows.Count > selectedIndex)
   2:  {
   3:      dataGridView1.Rows[selectedIndex].Selected = true;
   4:      dataGridView1.FirstDisplayedScrollingRowIndex = selectedIndex;
   5:  }

No comments: