Creating Persistent Columns
Go Up to Creating a Customized Grid
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
- Select the grid component in the form.
- Invoke the Columns editor by double clicking on the Columns property of the grid 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
- 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.
- 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.
- Click Close to apply the persistent columns to the grid and close the dialog box.
To create persistent columns individually
- 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).
- To associate a field with this new column, set the FieldName property in the Object Inspector.
- To set the title for the new column, expand the Title property in the Object Inspector and set its Caption property.
- 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 dataset of the grid. You can then add a persistent column at run time by calling the Add method for the column list: