I am making a .NET 4 WinForms application which reads data from a database and displays rows in a DGV. However the number of rows is larger than maximum number of rows that can fit on screen at once. To display all data, I need to scroll the DGV automatically until the last row and update the data source after that in order to refresh the DGV.
I found it's easy to do that by simply incrementing FirstDisplayedScrollingRowIndex
by one.
However the scrolling is too sharp. I would like it to scroll smoothly.
To do that, I have tried calling ScrollRows
method directly. That method is not public so I had to use Reflection like this:
var scrollRows = dgv.GetType().GetMethod("ScrollRows", BindingFlags.Instance | BindingFlags.NonPublic);
scrollRows.Invoke(dgv, new object[] { 1, -1, ScrollEventType.SmallIncrement });
I call this code from a timer_Tick
method which is triggered every 20 ms.
The DGV scrolls smoothly but it doesn't draw any row below those which were visible at the beginning.
Is there any way I can make it scroll smoothly AND display data properly?