public virtual void EnsureGroupVisible(ListViewGroup lvg)
{
if (!this.ShowGroups || lvg == null)
return;
int groupIndex = this.Groups.IndexOf(lvg);
if (groupIndex <= 0) {
// There is no easy way to scroll back to the beginning of the list
int delta = 0 - NativeMethods.GetScrollPosition(this, false);
NativeMethods.Scroll(this, 0, delta);
} else {
// Find the display rectangle of the last item in the previous group
ListViewGroup previousGroup = this.Groups[groupIndex - 1];
ListViewItem lastItemInGroup = previousGroup.Items[previousGroup.Items.Count - 1];
Rectangle r = this.GetItemRect(lastItemInGroup.Index);
// Scroll so that the last item of the previous group is just out of sight,
// which will make the desired group header visible.
int delta = r.Y + r.Height / 2;
NativeMethods.Scroll(this, 0, delta);
}
}