EhLib
ContentsIndexHome
PreviousUpNext
Customizing grid cells

Setting color dividing lines, the presence / absence of lines in various areas Grid.

It is possible to set the color and determine the presence or absence of dividing lines for the grid in general and for specific areas including the header area of the indicator area SubtitleFilter, data area and basement area (footer). 

Next properties are responsible for the presence of lines and colors in the grid: 

Presence / absence of values dgColLines, dgRowLines in property TDBGridEh.Options set the presence of vertical and horizontal lines for the Grid in general. 

By using sub-properties of this property TDBGridEh.GridLineParams you can control the color of the dark lines in the grid (DarkColor) and the color of bright lines (BrightColor), the color of the lines in the data, the presence of lines of data, and the color scheme of the lines. 

Sub-properties of the property TDBGridEh.GridLineParams:

Property name 
Property type 
Description 
DarkColor 
TColor 
Color dark lines. Used for areas of fixed cells, as well as areas within the meaning of which is meant shading dark lines.
ClDefault value determines what color will be determined automatically based on the current color scheme, the properties of Grid.Flat and activity of global change Themes.Active. 
BrightColor 
TColor 
Color bright lines. Used for data areas, and areas within the meaning of which is meant shading light lines.
ClDefault value determines the color will be automatically detected similarly DarkColor. 
DataVertColor 
TColor 
Color vertical lines in the data area. 
DataVertLines 
Boolean 
The existence of vertical lines in the data. 
DataHorzColor 
TColor 
Color of the horizontal lines in the data area. 
DataHorzLines 
Boolean 
The presence of horizontal lines in the data. 
DataBoundaryColor 
TColor 
Painted boundary lines grid (not to be confused with the client area) color DarkColor. 
GridBoundaries 
Boolean 
Paint boundary lines grid (not to be confused with the client area) color DarkColor. 
ColorScheme 
TDBGridLines
ColorSchemeEh 
Property determines the color scheme used to draw the dividing lines for which a color clDefault.
Property can contain the following values:

  • glcsDefaultEh - Use the default color scheme.
  • glcsClassicEh - The classic filling.Black lines for fixed areas. Gray lines for the data area.
  • glcsFlatEh - On
  • glcsThemedEh -

 

VertEmptySpaceStyle 
TDrawEmpty
SpaceStyle 
VertEmptySpaceStyle property specifies the mode of filling lines and columns for the empty space between the last record of the grid and the bottom of the window.
Property can contain the following values:

  • dessNonEh - Do not paint.
  • dessSolidEh - Use solid dividing lines and colors of the columns.
  • dessGradiendEh - use gradient shading solid dividing lines and colors of the columns.

 

Showing bitmaps in data cells depending on the field values.

TDBGridEh allows to show bitmaps from TImageList component depending on the field values. In order to show bitmaps you need fill list Column.KeyList property by the possible field values (every value in the separated line) and set Column.ImageList property by the TImageList control that has the bitmaps. Every image in ImageList corresponds to the string line in the KeyList property. You can also set Column.NotInKeyListIndex property to the index of bitmap that will be shown if the field's value does not correspond to any value in the KeyList (for instance you can set index of image for Null field value). At run time you can’t edit cells with bitmaps. Use SPACE key or mouse click to set value from next line of Column.KeyList to the field. Use Shift+SPACE key or Shift+Mouse click to set value from previous line Column.KeyList. You can also set Column.DblClickNextval to True to allow changing values in cell by double mouse clicking.

Showing pictures from DataSet fields in the grid cells.

DBGridEh can display images in the data cells in the following formats: 

BMP, JPeg, 

GIF - From Developer Studio 2007 

PNG - From RAD Studio 2009. 

To enable the display of graphics data set DBGridEh.DrawGraphicData to True. The grid will display graphical information for the fields of type TGraphicField and TBlobField who BlobType = ftGraphic.Default. DBGridEh recognizes only format like TBitmap. For the addition of graphical modules use the property DBGridEh.IncludeImageModules: TIncludeImageModulesEh.

TIncludeImageModuleEh = (
iimJpegImageModuleEh, // plug-in to display the data in a format JPeg
iimGIFImageModuleEh,  // plug-in to display the data in the format of GIF
iimPNGImageModuleEh   // plug-in to display the data in PNG
);

This property should only be used in Design-Time compilation via IDE. Setting this property causes the IDE to add additional modules in the module uses the form.

Checkboxes for Boolean and non Boolean fields.

Grid automatically shows checkboxes for Boolean fields. To show checkboxes for no Boolean fields, fill first line of Column.KeyList property by value (or values) that corresponds to the checked state of the checkbox. Fill second line for non-checked state, and set Column.Checkboxes property to True. One line of KeyList can contain more than one value. In that case every value must be separated by semicolon.

Data row height.

Use RowHeight and RowLines properties to specify the height of data row. Full height of data row is calculated as height in text lines of RowLines plus RowHeight. Set RowSizingAllowed to True value so that user can change height of row using mouse at run time. 

Set Column.WordWrap to True value to break a long text in data row to a multiline. In reality, text will be wrapped only when height of row is bigger than height of one text line.

Individual height of each data row.

TDBGridEh can work in mode when the height of every row is calculated dynamically depending on the text in the grid cells or size of image in the cell (When DrawGraphicData value is True). Include dghAutoFitRowHeight in OptionsEh property to force grid to calculate height for every row. This mode works only when the grid is connected to the DataSet of TMemTableEh type and TMemTableEh is not in TreeView mode. When dghAutoFitRowHeight is included, grid calculates the height of the row dynamically using cell text (TColumnEh.WordWrap property also influence it) and for column the fields of which have ftGraphic type. To avoid surplus recalculation, grid recalculates heights, but not for after every change of properties. For instance, grid does not update heights if the Font property was changed. In such cases it is necessary to call UpdateAllDataRowHeights method. For more flexible calculation of the heights the grid has an OnGetRowHeight event, in which you can specify the height of row. During the event calling, the MemTableEh positions on record and we can calculate the height of this record, so you can use MemTableEh properties to access fields values.

Draw memo fields.

To draw memo fields as text set DrawMemoText to True.

Customize cells font attributes and color.

TDBGridEh properties Font and Color describe the font and color which is used to draw cells in the grid. 

TColumnEh properties Font and Color describe the font and color which is used to draw cells in the specified column.

Events to customize cell’s font attributes and color.

There are several events that allow you to customize cell’s font attributes and color before the cell data will be drawn. In the time of calling these events the DataSet is positioned on the record that need to draw, so in the events you can access field values using such methods as TDataSet.FieldByName(..).Value. Do not change grid properties or columns properties in these events. It can bring to recirculation of the program. 

TDBGridEh.OnDrawColumnCell 

Write OnDrawColumnCell event to overload the standard method of the drawing cell. This event is called after standard drawing, so the information will be drawn above standard-drawn contents of cell. You may print the additional data, using methods of TDBGridEh(Sender).Canvas property. 

TDBGridEh.OnDrawDataCell 

Do not write an OnDrawDataCell event handler. OnDrawDataCell is obsolete and included for backward compatibility. 

TColumnEh.OnAdvDrawDataCell or TDBGridEh.OnAdvDrawDataCell 

Write this event to draw data in the grid cell. In code of the event we set Processed parameter in True value to define that the process of drawing was performed in event. Otherwise grid will call method for default drawing of cell data. You may, if necessary, change such parameters as ARect or Params. After changing the parameters call Grid.DefaultDrawColumnDataCell method and set Processed to True value. You can also leave Processed parameter in False state and don’t call Grid.DefaultDrawColumnDataCell. In that case, grid will call default drawing procedure using changed parameters. Use Grid.Canvas property to draw data in the cell by yourself. 

TDBGridEh.OnGetCellParams or TColumnEh.OnGetCellParams 

Write OnGetCellParams event to set such parameters as Font, cell color or other parameters of cell before cell will be drawn. If it is needed to change parameters only in a specified column then use column event - TColumnEh.OnGetCellParams. In this event you may change Font, Color, Alignment, ImageIndex, Text, checkbox's state and also such properties of a Params parameter as:

BlankCell 
Boolean 
Set this property to true to show cell as an empty cell with 3D border. 
SuppressActiveCellColor 
Boolean 
Set this property to forbid the color of active cell to overlay the color that is set in Background property. 
TextEditing 
Boolean 
Set this property to forbid showing of cell text editor. 

These events are also called when grid request Font and Color for in-place editor. 

If you want to draw data by yourself use OnAdvDrawDataCell event.

Drawing of a ProgressBar shaped image in the Grid’s cell.

 

Grid doesn’t allow customizing column to show ProgressBar shaped image, but there is a procedure DrawProgressBarEh in the ToolCtrlsEh module. You can use it to draw image of ProgressBar when an event of custom drawing of a Grid’s cell is used. 

Below you can see an example of using of the DrawProgressBarEh procedure:

procedure TForm1.DBGridEh6Columns3AdvDrawDataCell(Sender: TCustomDBGridEh;
  Cell, AreaCell: TGridCoord; Column: TColumnEh; const ARect: TRect;
  var Params: TColCellParamsEh; var Processed: Boolean);
begin
  Sender.DefaultDrawColumnDataCell(Cell, AreaCell, Column, ARect, Params);

  DrawProgressBarEh(mtTable1.FieldByName('ItemsTotal').AsFloat, 0, 50000,
     Sender.Canvas, ARect, clSkyBlue, cl3DDkShadow, clNone);
  Processed := True;
end;
Default values for column properties.

To set default values for column properties use ColumnDefValues property. New created columns will take property values from ColumnDefValues properties and will hold them till first assign new value.

Copyright (c) 1998-2013. All rights reserved.
What do you think about this topic? Send feedback!