private void scrollToSelectionIfNeeded(PDSection s) { if (s.HasNoSelection()) return; Rectangle selectedRowBounds = s.SelectedRowBounds; // translate to the coordinates of the pdsection container panel (the one added for padding purposes) selectedRowBounds.Offset(s.Parent.Location); // Top edge visible? if (panel2.ClientRectangle.Height - selectedRowBounds.Top > 0 && selectedRowBounds.Top > 0) { // Bottom edge visible? if (panel2.ClientRectangle.Height - selectedRowBounds.Bottom > 0 && selectedRowBounds.Bottom > 0) { // The entire selected row is in view, no need to move return; } } panel2.ForceScrollTo(s); }