Saturday, March 19, 2011

DataGridView not Updating when DataSource modified

I had this problem. I managed to solve it as follows:

int x = dgvMetronomeSpeeds.FirstDisplayedScrollingRowIndex;
dgvMetronomeSpeeds.DataSource = null;
m_metronomeSpeeds.Add(new Integer(0));
dgvMetronomeSpeeds.DataSource = m_metronomeSpeeds;
dgvMetronomeSpeeds.FirstDisplayedScrollingRowIndex = x;

If you don't save and restore the FirstDisplayedScrollingRowIndex, then the user loses his/her scroll position.

other keywords - c#, msdn, .NET, scrolling

No comments:

Post a Comment