Controlling Grid Drawing

From RAD Studio
Jump to: navigation, search

Go Up to Viewing and Editing Data with TDBGrid


Your first level of control over how a grid control draws itself is setting column properties. The grid automatically uses the font, color, and alignment properties of a column to draw the cells of that column. The text of data fields is drawn using the DisplayFormat or EditFormat properties of the field component associated with the column.

You can augment the default grid display logic with code in the DBGrids.OnDrawColumnCell event of a grid. If the grid's DefaultDrawing property is True, all the normal drawing is performed before your OnDrawColumnCell event handler is called. Your code can then draw on top of the default display. This is primarily useful when you have defined a blank persistent column and want to draw special graphics in that cells of the column.

If you want to replace the drawing logic of the grid entirely, set DefaultDrawing to False and place your drawing code in the OnDrawColumnCell event of the grid. If you want to replace the drawing logic only in certain columns or for certain field data types, you can call the DefaultDrawColumnCell inside your OnDrawColumnCell event handler to have the grid use its normal drawing code for selected columns. This reduces the amount of work you have to do if you only want to change the way Boolean field types are drawn, for example.

See Also