I have some trouble with setting the last row in my datagridview selected. I select the last row this way:
if (grid.Rows.Count > 0)
{
try
{
gr
To avoid the IndexOutOfRangeException make sure only to select a visible row. I suggest:
// Find last visible row
DataGridViewRow row = dataGridView1.Rows.Cast().Where(r => r.Visible).Last();
// scroll to last row if necessary
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.IndexOf(row);
// select row
row.Selected = true;