Wednesday, July 8, 2009

Displaying Large Quantities of Data in Windows Controls


This article and accompanying code was written to demonstrate a technique for displaying very large quantities of data in a visual control, with very little performance degradation.


It is a common situation in working with large quantities of data, where this data needs to be presented to the user. Lists and trees are often used for this purpose. Many times, the programmer attempts to load one of these controls with an entire data set. The problem arises when an increasing number of items are added to these controls; memory usage increases and performance decreases to the point that this solution is no longer acceptable.

This article presents a technique to display very large data sets with no performance degradation.

This technique could easily be adapted to a variety of .NET controls, as well as other platforms, such as Java Swing controls.

Strategy for Displaying Large Quantities of Data in a ListView

The approach for this example is to have a list control that will only contain data items that are visible to the user, not the entire data set. The existing .NET ListView component is used, coupled with a VScrollBar, which is 'manually' adjusted to reflect the quantity of data being represented. Since the ListView will only contain exactly the number of data items (ListViewItem) that can be displayed, the internal vertical scroll bar should never show. Therefore, it is necessary to manage a separate slider that accurately reflects the quantity of data being represented. This control can be thought of as being a sliding window that moves up and down over a large set of data.

As ListViewItems move out of view, they are deleted, and as new ones come into view, they are added, so that the list only contains a maximum of the number of items that can be viewed by the user.

Pieces of the Puzzle

The HighPerformanceListView is a new composite control that encapsulates a .NET ListView control and a VScrollBar control. This control can be added to the tool box and dropped onto a Form. To programmatically provide the data in a generic manner, this control uses an object implementing an IHighPerformanceListViewProvider interface. This object supplies the supplemental functionality needed by the ListView control to determine the column headers being displayed, and to provide ListViewItems that represent one item of data.

See full detail:

No comments: