Business data tends to organize itself into rows and columns (witness the success of Lotus123, Excel and other spreadsheet software). For the .NET UI developer, the Windows DataGridView is indispensible in that it provides a quick way to organize business data into rows and columns. Sorting, Paging etc. are usually either built in or fairly straightforward to implement.
While the DataGridView control is flexible enough to display any IList as its datasource, it starts running into some performance problems for large volumes of data. The Virtual mode in the Windows DataGridView control was designed for just such a purpose – to handle large volumes of data. It does this by postponing the rendering of the entire data all at once – and only renders a fixed number of rows and columns at a time. As one tries to scroll down (or up), new data is rendered at that very instant – using predefined events (CellValueNeeded event in the DataGridView).
However, as we encountered early on in our project, even the virtual mode starts showing sluggishness for larger amounts of data (in fact, even at just a few KBs of data). What is one to do if one needs to display data in a grid – and also needs to display LOTS and LOTS of it?
Syncfusion is a 3rd Party UI library – which contains several advanced controls in its toolbox. It offers a GridControl with all the basic grid display capabilities. And then it offers something called a GridGroupingControl – which is a GridControl on steroids. For instance, if one is interested in grouping by not one – but multiple columns, the grouping grid does it with just a couple of lines of code. If one is interested in nested grids (something that will take days to implement for the WinForms DataGridView), the GroupingGridControl provides that out of the box as well. If one is interested in sorting, paging etc. available out of the box, Syncfusion provides that as well.
However, the main reason our team chose Syncfusion was simple – performance. Syncfusion provides a GridControl class which also has a virtual mode built in. The virtual mode in Syncfusion’s GridControl works in a similar fashion to Windows DataGridView – by rendering more rows and columns as the user tries to scroll up or down on the grid. The actual events that Syncfusion uses are QueryCellInfo and QueryRowCount (see attached code).
This article uses a simple ArrayList (of Customer objects) – and lets you experiment with the performance of the DataGridView as the number of items grows. In the sample, the ArrayList of Customers is set to a size of 10,000. At this size, the performance difference between the Windows DatagridView and Syncfusion’s GridControl are already visible. If you try a larger size list, the differences will be even more evident.
I was actually going to put in some ‘load times’ in the sample code for comparing the two grids. However – what is important is not so much the load time – as the ‘rendering time’. As one can see by just plain visual inspection, the Windows DataGridView renders a lot slower than Syncfusion’s GridControl.
Summary
Today’s business applications deal with large amounts of data. The actual number of rows does not have to be large for the ‘displayable’ data to be large. One can have a few large objects in a relatively small list – to constitute a large amount of ‘display’ data. The DataGrid is the most commonly used control for displaying data in a Windows Client application. Whether it is a WinForms DataGridView or a WPF datagrid, the datagrid is usually the first choice for displaying complex business data.
This article provides a side by side performance comparison of the WinForms DataGridView and Syncfusion’s GridControl. Using each of these grids to display the exact same data (10,000 unique customer data records), one can see the different rendering speeds. The DataGridView starts deteriorating in performance at just a few KBs of display data.
Syncfusion’s GridControl offers a superfast alternative to the WinForms DataGridView. It is quite possible that other vendors (Infragistics, Telerik etc.) offer equally compelling options. I am looking forward to evaluating Infragistics’ latest UltraWinGrid in the near future – and will post an update to this blog.
Download Solution - VirtualGrids.zip