Hi James,
It's not just a DataGridView; it happens with any control that's higher than the panel, eg Infragistics UltraWinGrid, RichTextBox.
If your DataGridView is the only control in the panel, just set the Dock to Fill and let the dataGridView handle scrolling on it's own.
Any way, back to the point. This is caused by the ScrollToControl event being fired automatically by the ScrollableControl class, and the event handler scrolling to show the top left of the control that got focus. This behavior is not helpful
when the scrollable container control only contains one control. I was very frustrated by this behavior until I found out how to stop it.
The way to stop this behavior is to override the ScrollToControl event handler, like this:
class PanelNoScrollOnFocus : Panel
{
protected override System.Drawing.Point ScrollToControl(Control activeControl)
{
return DisplayRectangle.Location;
}
}
Best Wishes,
Helen Zhou
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.