Grid Customization
.Net Grid provides broad functionality of displaying various data grid elements, such as cells, rows, headers and columns.
There two ways for data grid customization:
- Setting specific appearance of the element via Appearance property. For instance, Grid.Appearance, Header.Appearance, Column.Appearance, Row.Appearance, Cell.Appearance. All information about colors, fonts etc. is stored in memory. Therefore setting of this property is more suitable for Grid, Header, Column. A programmer should not use this property on Rows and Cells, as it will consume lot of memory.
- Setting specific parameters in the very moment of painting. For most efficient memory usage, this information is stored in memory for only a short period of time. To implement this feature, a programmer should subscribe to a specific event such as Grid.PaintCell,
Grid.PaintRow, Grid.PaintHeader etc.
The PaintXXXEventArgs contains the following information:
- Full and clipped sizes of the painted element
- Graphics object
- Colors and parameters used for elemebt painting (they can be altered)
- Methods for painting every single part of an element (for a Cell there are methods for painting background, text, selection, focus etc.)
- Painting filter – PaintPart, which allows to skip a certain part of an element (partial painting)
- PaintAll() method that paints all elements defined in the PaintPart filter
- Handled property that forbids a data grid to perform default painting
Note that the whole painting process is accumulated in PaintXXXEventArgs and consists of the following: a data grid creates PaintXXXEventArgs object, sets default parameters, fires Pain event, and if Handled property is set to false, invokes PaintAll() method. This mechanism is used to paint all elements of the .Net Grid – cells, rows, columns, headers, hierarchy tree etc.
We have intentionally described the process of painting in details to show broad and rich abilities of data grid customization. In other words, you may customize any parameters, some painted elements (cell, column) and even use Graphics object to manipulate the data grid. Even better, this approach enables you to define a painting sequence. For example, you may perform some default actions and then finish drawing with the Graphics object, or do it vice versa!
Back to .Net Grid Features