public void EnsureVisible (int index)
{
if (index < 0 || index >= items.Count || scrollable == false || updating)
return;
Rectangle view_rect = item_control.ClientRectangle;
// Avoid direct access to items in virtual mode, and use item bounds otherwise, since we could have reordered items
Rectangle bounds = virtual_mode ? new Rectangle (GetItemLocation (index), ItemSize) : items [index].Bounds;
if (view == View.Details && header_style != ColumnHeaderStyle.None) {
view_rect.Y += header_control.Height;
view_rect.Height -= header_control.Height;
}
if (view_rect.Contains (bounds))
return;
if (View != View.Details) {
if (bounds.Left < 0)
h_scroll.Value += bounds.Left;
else if (bounds.Right > view_rect.Right)
h_scroll.Value += (bounds.Right - view_rect.Right);
}
if (bounds.Top < view_rect.Y)
v_scroll.Value += bounds.Top - view_rect.Y;
else if (bounds.Bottom > view_rect.Bottom)
v_scroll.Value += (bounds.Bottom - view_rect.Bottom);
}