public bool EnsureVisible(int row, int column)
{
if (!this.Scrollable || (!this.HScroll && !this.VScroll) || row == -1)
{
return false;
}
if (column == -1)
{
if (this.FocusedCell.Column != -1)
{
column = this.FocusedCell.Column;
}
else
{
column = 0;
}
}
int hscrollVal = this.hScrollBar.Value;
int vscrollVal = this.vScrollBar.Value;
if (this.HScroll)
{
if (column < 0)
{
column = 0;
}
else if (column >= this.ColumnCount)
{
column = this.ColumnCount - 1;
}
if (this.ColumnModel.Columns[column].Visible)
{
if (this.ColumnModel.Columns[column].Left < this.hScrollBar.Value)
{
hscrollVal = this.ColumnModel.Columns[column].Left;
}
else if (this.ColumnModel.Columns[column].Right > this.hScrollBar.Value + this.CellDataRect.Width)
{
if (this.ColumnModel.Columns[column].Width > this.CellDataRect.Width)
{
hscrollVal = this.ColumnModel.Columns[column].Left;
}
else
{
hscrollVal = this.ColumnModel.Columns[column].Right - this.CellDataRect.Width;
}
}
if (hscrollVal > this.hScrollBar.Maximum - this.hScrollBar.LargeChange)
{
hscrollVal = this.hScrollBar.Maximum - this.hScrollBar.LargeChange;
}
}
}
if (this.VScroll)
{
if (row < 0)
{
vscrollVal = 0;
}
else if (row >= this.RowCount)
{
vscrollVal = this.RowCount - 1;
}
else
{
int hidden = tableModel.Rows.HiddenRowCountBefore(row);
if (row < vscrollVal)
{
vscrollVal = row;
}
else if (row - hidden > vscrollVal + this.vScrollBar.LargeChange)
{
vscrollVal += row - (vscrollVal + this.vScrollBar.LargeChange);
}
}
if (vscrollVal > this.vScrollBar.Maximum - this.vScrollBar.LargeChange)
{
vscrollVal = (this.vScrollBar.Maximum - this.vScrollBar.LargeChange) + 1;
}
}
if (this.RowRect(row).Bottom > this.CellDataRect.Bottom)
{
vscrollVal++;
}
var moved =
SetScrollValue(this.hScrollBar, hscrollVal)
| SetScrollValue(this.vScrollBar, vscrollVal);
if (moved)
{
this.Invalidate(this.PseudoClientRect);
}
return moved;
}