private int EnsureSafeVScrollValue(int newValue)
{
int newTopRowIndex = newValue;
int visibleRows = this.vScrollBar.LargeChange - 1;
if (newTopRowIndex < 0)
{
// Can get here with the mousewheel going up
newTopRowIndex = 0;
}
else if (newTopRowIndex > this.vScrollBar.Maximum - visibleRows)
{
// Can get here with the mousewheel going down
newTopRowIndex = this.vScrollBar.Maximum - visibleRows;
}
return newTopRowIndex;
}