Icon Binding Controls to DataSets

The controls in the standard component library can be used in both an unbound and bound manner. A control is considered bound when it is explicitly attached to a dataset and one or more columns in the dataset. Most controls bind to a specific dataset column, while certain controls like the TGrid control can bind to multiple dataset columns.

Once a control is bound to a dataset, it will automatically update its contents in response to changes in the dataset. For example, if you insert a new row in the dataset using the TDataSet Insert method, then the control will automatically repopulate with the value from the new row.

Binding to a DataSet
To bind a control to a specific dataset, assign an existing TDataSet instance to the DataSet property of the control. This can be done at design-time or run-time.

Information If the TDataSet instance that is assigned to the DataSet property is deleted, the control will automatically assign a value of nil to the DataSet property and the control will become unbound.

However, simply assigning the DataSet property is insufficient for binding a control to a dataset - you must also specify which column in the dataset to bind to. For most controls, this is done by assigning a column name to the DataColumn property. For the TGrid component, you must assign a column name to the DataColumn property of each TGridColumn in the grid that you wish to be bound to the dataset.

Information The TGrid component allows you to to mix bound and un-bound columns within the same grid control.

Auto-Editing of Bound Controls
The value of the TDataSet AutoEdit property determines whether modifications to the contents of bound controls are allowed when the dataset is not in an editable state (TDataSet State property is dsInsert or dsUpdate). If the AutoEdit property is True, then any modification to a bound control will cause the attached dataset to insert a new row if the dataset is empty, or begin updating the current row if the dataset is not empty. If the AutoEdit property is False, then bound controls are effectively read-only until either a new row is inserted or an existing row is updated in the dataset.

Information The TGrid control has two properties that can still enable a user to insert or delete rows in a bound grid. They are the AllowInserts and AllowDeletes properties, respectively. Be sure to set these properties to False if you do not want to allow a user to automatically insert or delete rows by using keystrokes in the grid.

Auto-Editing and Read-Only Columns
Dataset columns can be defined as calculated or read-only using the TDataColumn Calculated and ReadOnly properties, respectively. Any controls bound to a calculated or read-only column will not be editable, and will behave as though the dataset's AutoEdit property is set to False.
Image