Nov 16, 2009
I have a DataGridView which reads data from a custom (CSLA) list object. The dataset might have 100,000 records, and obviously I don't want to show them all at once because, for one, it would take ages to load.I think it would be nice if I could read the first (for instance) 20 records, and make it so upon scrolling to the end of the list, it reads the next 20 and adds them to the DataGridView.
View 2 Replies
I have experimented with various ways of doing this, mostly using a custom class inheriting from DataGridView to capture scroll events and raising an event which adds new records. I will include the code below:
Public Class TestDGV
Public Sub New()
Though this (sort of) works, it can be buggy. The biggest problem was that if you used the mouse to scroll the DataGrid, it would get stuck in a loop as it process the scrollbar's ValueChanged event after the data was added. That's why I added ScrollbarOff and ScrollbarOn - I call them before and after getting new records, which disables the scrollbar temporarily.
The problem with that is that after the scrollbar is re-enabled, it doesn't keep track of the current mouse state, so if you hold down the 'Down' button with the mouse (or click on part of the scrollbar) it stops scrolling after it has added the new records, and you have to click it again.