This sample illustrates how to optimize a grid for fast update scenarios. It provides a specialized volatile data cache that works best for non-virtual grids with a limited number of rows and columns. It also shows how to use the GDI interop routines to increase maximum performance.
Features
Every twenty milliseconds, a timer event is raised.
In the event handler, it changes all the cell values three times and it inserts and removes one-third of the rows and columns.
The PrepareViewStyleInfo is used to provide a red background for specific cells.
This sample builds on the performance sample of OneTimeQueryCellInfo, and uses the same derived classes most of the time.
In this sample, the derived grid control has additional properties and methods that are used to illustrate additional performance enhancements.
Here are the property settings of the derived Grid Control that affects the performance. The first three are properties of the derived class, and the latter three are inherited from the grid control.
Use GDI - Indicates whether the grid should use a GDI or a GDI+ to manage the drawing of text and backgrounds. In some situations, it would be more efficient to use a GDI drawing. This is implemented by the derived grid in the OnDrawCellDisplayText and the OnFillRectangleHook overrides. It uses call-to-static helper methods in the library code that accesses the GDI routines through the interop.
Use Double Buffer- Controls double buffering support when the .NET Framework is used. With double buffering turned on, the grid must call base.OnPaintBackground so that the background is drawn properly.
Use Grid Non-Virtual Data Cache- Controls the raising of QueryCellInfo just once or constantly. This is discussed in detail in the OneTimeQueryCellInfo performance sample.
Optimize Draw Background- Combine cells having the same background in order to draw them with one paint operation instead of drawing the background for each cell individually.
Optimize Insert-Remove Cells- Specifies if inserting and removing cells should be optimized by scrolling the window content and only invalidating new cells, instead of redrawing the whole display.
Supports PrepareViewStyleInfo- By default, the grid will make a copy of any style object before painting and will call the PrepareViewStyleInfo event. Changes that are made to the style object will then be discarded after the painting. The same is true with DrawCell and other events. Having a copy of the style will enable you to change the style object just for the purpose of drawing. If you do not have a need for this, and want to increase the scrolling performance of the grid, then set this property to false.