Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataGridView inside a panel jumps to beginning of list after panel gets scrolled

I have a DataGridView inside a panel. The scrolling is disabled on the DataGridView but instead is done on the panel. By doing so I achieve pixel based scrolling of the DataGridView. I scroll as following:

dgvPanel.AutoScrollPosition = value;

However, the problem is that after changing the scroll bar position, if I click on the DataGridView - it jumps back to the beginning of the list. What could cause this?

like image 396
eYe Avatar asked Mar 18 '15 13:03

eYe


1 Answers

Replace the panel you are using with this one, which overrides the ScrollToControl function the default panel is using to make sure the control is visible:

public class PanelEx : Panel {
  protected override Point ScrollToControl(Control activeControl) {
    //return base.ScrollToControl(activeControl);
    return this.AutoScrollPosition;
  }
}
like image 59
LarsTech Avatar answered Sep 24 '22 10:09

LarsTech