Creating a Customized Grid

From RAD Studio
Jump to: navigation, search

Go Up to Viewing and Editing Data with TDBGrid


A customized grid is one for which you define persistent column objects that describe how a column appears and how the data in the column is displayed. A customized grid lets you configure multiple grids to present different views of the same dataset (different column orders, different field choices, and different column colors and fonts, for example). A customized grid also enables you to let users modify the appearance of the grid at run time without affecting the fields used by the grid or the field order of the dataset.

Customized grids are best used with datasets whose structure is known at design time. Because they expect field names established at design time to exist in the dataset, customized grids are not well suited to browsing arbitrary tables selected at run time.

Understanding persistent columns

When you create persistent column objects for a grid, they are only loosely associated with underlying fields in the dataset of a grid. Default property values for persistent columns are dynamically fetched from a default source (the associated field or the grid itself) until a value is assigned to the column property. Until you assign a column property a value, its value changes as its default source changes. Once you assign a value to a column property, it no longer changes when its default source changes.

For example, the default source for a column title caption is the DisplayLabel property of an associated field. If you modify the DisplayLabelproperty, the column title reflects that change immediately. If you then assign a string to the column title's caption, the tile caption becomes independent of the DisplayLabel property of the associated field. Subsequent changes to the field's DisplayLabel property no longer affect the title of the column.

Persistent columns exist independently from field components with which they are associated. In fact, persistent columns do not have to be associated with field objects at all. If the FieldName property of a persistant column is blank, or if the field name does not match the name of any field in the current dataset of the grid, the Field property of the column is NULL and the column is drawn with blank cells. If you override the default drawing method of the cell, you can display your own custom information in the blank cells. For example, you can use a blank column to display aggregated values on the last record of a group of records that the aggregate summarizes. Another possibility is to display a bitmap or bar chart that graphically depicts some aspect of the data of the record.

Two or more persistent columns can be associated with the same field in a dataset. For example, you might display a part number field at the left and right extremes of a wide grid to make it easier to find the part number without having to scroll the grid.

Note: Because persistent columns do not have to be associated with a field in a dataset, and because multiple columns can reference the same field, a customized FieldCount property of the grid can be less than or equal to the column count of the grid. Also note that if the currently selected column in a customized grid is not associated with a field, the SelectedField property of the grid is NULL and the SelectedIndexproperty is -1.

Persistent columns can be configured to display grid cells as a combo box drop-down list of lookup values from another dataset or from a static pick list, or as an ellipsis button (...) in a cell that can be clicked upon to launch special data viewers or dialogs related to the current cell.

The following topics provide additional information about persistent columns:

See Also