private static void EnsureVisibleRow(DataGridView view, int rowToShow)
{
if (rowToShow >= 0 && rowToShow < view.RowCount)
{
var countVisible = view.DisplayedRowCount(false);
var firstVisible = view.FirstDisplayedScrollingRowIndex;
if (rowToShow < firstVisible)
{
view.FirstDisplayedScrollingRowIndex = rowToShow;
}
else if (rowToShow >= firstVisible + countVisible)
{
view.FirstDisplayedScrollingRowIndex = rowToShow - countVisible + 1;
}
}
}
However, keep in mind when you do this, that adding new rows and trying to keep the last row added visible will interfere with the user's ability to navigate the control.
I think you might be better off showing the last item added as a separate textbox or something along that line.