RAD Studio |  |

Creating Persistent Columns
See Also
Collapse All

To customize the appearance of grid at design time, you invoke the Columns editor to create a set of persistent column objects for the grid. At runtime, the State property for a grid with persistent column objects is automatically set to csCustomized.

To create persistent columns for a grid control

1. Select the grid component in the form.
2. Invoke the Columns editor by double clicking on the grid's Columns property in the Object Inspector.

The Columns list box displays the persistent columns that have been defined for the selected grid. When you first bring up the Columns editor, this list is empty because the grid is in its default state, containing only dynamic columns.

You can create persistent columns for all fields in a dataset at once, or you can create persistent columns on an individual basis.

To create persistent columns for all fields

1. Right-click the grid to invoke the context menu and choose Add All Fields. Note that if the grid is not already associated with a data source, Add All Fields is disabled. Associate the grid with a data source that has an active dataset before choosing Add All Fields.
2. If the grid already contains persistent columns, a dialog box asks if you want to delete the existing columns, or append to the column set. If you choose Yes, any existing persistent column information is removed, and all fields in the current dataset are inserted by field name according to their order in the dataset. If you choose No, any existing persistent column information is retained, and new column information, based on any additional fields in the dataset, are appended to the dataset.
3. Click Close to apply the persistent columns to the grid and close the dialog box.

To create persistent columns individually

1. Choose the Add button in the Columns editor. The new column will be selected in the list box. The new column is given a sequential number and default name (for example, 0 - TColumn).
2. To associate a field with this new column, set the FieldName property in the Object Inspector.
3. To set the title for the new column, expand the Title property in the Object Inspector and set its Caption property.
4. Close the Columns editor to apply the persistent columns to the grid and close the dialog box.

At runtime, you can switch to persistent columns by assigning csCustomized to the Columns.State property. Any existing columns in the grid are destroyed and new persistent columns are built for each field in the grid's dataset. You can then add a persistent column at runtime by calling the Add method for the column list:
Copy Code

    DBGrid1.Columns.Add;

Copy Code

    DBGrid1->Columns->Add();

See Also

Deleting Persistent Columns

Arranging the Order of Persistent Columns

Defining a Lookup List Column

Putting a Button in a Column

Setting Column Properties at Design Time

Restoring Default Values to a Column

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!