From: MS on
I have a project that uses a DataGridView control. I allow the user to move
the selected row up or down using a couple buttons on the form. This works
great except if the list of items is long and the vertical scroll bar is
used when the item is moved beyond the items being displayed the user no
longer sees the item and has to use the scroll bar to move up or down to
view the item that was being moved. Is there a way to get the DataGridView
form to automatically scroll so the selected item is always visible? Here
is the code I am using in the Down button to move the selected row down.

if (dgSort.SelectedRows.Count != 0)
{

int index = dgSort.SelectedRows[0].Index;

if (index < dgSort.Rows.Count-1)

{

for (int j = 0; j < this.dgSort.Columns.Count; j++)

{

if (j != 2)

{

object tmp = this.dgSort[j, dgSort.SelectedRows[0].Index].Value;

this.dgSort[j, dgSort.SelectedRows[0].Index].Value = this.dgSort[j,
dgSort.SelectedRows[0].Index + 1].Value;

this.dgSort[j, dgSort.SelectedRows[0].Index + 1].Value = tmp;

}

}

dgSort.Rows[index + 1].Selected = true;

}

}



Thanks for you help,

tk