RectControl → Control → Object

DataControl Class

Allows the user to browse among records in a database table by clicking buttons. It consists of First Record, Previous Record, Next Record, and Last Record navigation buttons and a label that displays the Caption property.

Events
Delete | MovePrevious
Insert | Reposition
MoveFirst | Update
MoveLast | Validate
MoveNext |

Methods
Delete | MoveNext | RecordSet
FieldCount | MovePrevious | Row
Insert | MoveTo | RowCount
MoveFirst | NewRecord | RunQuery
MoveLast | RecordCount | Update

# Notes

Built-in events fire when the user clicks any button. Methods allow you to navigate among rows programmatically.

A DataControl is designed to display data using CheckBoxes, EditFields, ListBoxes, StaticTexts, PopupMenus, and ComboBoxes. You can also create custom classes that are based on any of these classes and use them in conjunction with a DataControl.

Each of these controls (or their subclasses) has two properties that are specific to the DataControl: DataSource and DataField. DataSource accepts a DataControl object and DataField accepts the name of a field in the table to which the DataControl is linked. You set up a database interface by linking a DataControl to a table in a database and then linking each field whose values you wish to display to a CheckBox, EditField, ListBox, StaticText, PopupMenu or ComboBox using the DataField and DataSource properties.

# Properties

Property | Type | Description
--- | --- | ---
Caption | String | The text shown between the two sets of navigation buttons.
Commit | Boolean | If True, automatically commits inserts, updates, and deletions to the database.
Database | Database | The database to which the control is linked.
Encoding | TextEncoding | When the DataControl retrieves a string value, it will set the Encoding of the string and when you update or insert a string value using the DataControl. REALbasic will convert that encoding to this encoding. The default Encoding is UTF8.
ReadOnly | Boolean | Set to True to prevent the user from adding, modifying, or deleting records. When True, the record navigation controls are disabled.
RecordLocked | Boolean | A value of True means that the record is locked, preventing changes to the record; False indicates that it is unlocked.
RecordSet | RecordSet | The RecordSet managed by the DataControl.
SQLQuery | String | SQL query used to obtain the default RecordSet.
TableName | String | Name of the table in Database whose records will be displayed by the controls linked to the DataControl.

You use a DataControl by creating a window that uses Checkboxes, EditFields, ListBoxes, PopupMenus, ComboBoxes, or StaticText controls to display and edit data. Each of these controls has two properties that are meaningful only when used in conjunction with a DataControl, DataField and DataSource.

You can use Object Binding to bind objects such as a PushButton to a DataControl. Supported actions are: Add, Insert, Update, and Delete Record when the PushButton is pushed. To create an object bind, select the control and the DataControl and then choose Project . Add . Binding (If you have added the Add Binding button to the Window Editor toolbar, you can click that button to display the dialog). A dialog box that lists all possible bindings between the selected control and the DataControl will be listed. Choose the desired type of binding.

To remove a binding, choose View . List Bindings. A dialog that lists all the current bindings in the window appears. Highlight the binding you wish to remove and then click the Delete button. (If you have added the List Bindings button to the Window Editor toolbar, you can click that button to display the dialog.)

When you build an interface using a DataControl, it makes it easy to modify and save records. When the user saves changes, it automatically updates the values in the database back end with the values in the controls bound to the DataControl. If you need to update other values, you need to do it conventionally using the RecordSet method of the DataControl.

# See Also

Database, DatabaseField, DatabaseRecord, RecordSet classes.