Share via


Controls and Data Concepts

You can have two types of controls on your forms: controls that are bound to data and controls that are not. When users interact with bound controls, the values that they enter or choose are stored in the data source, which can be a table field, a cursor field, or a variable. You bind a control to data by setting its ControlSource property, or, in the case of grids, its RecordSource property.

If you do not set the ControlSource property of a control, the value that the user enters or chooses in the control is only stored as a property setting. The value is not written to disk or stored in memory beyond the lifetime of the control.

Effect of a ControlSource Property Setting on Controls

Control Effect
Check box If the ControlSource is a field in a table, then NULL values, logical values true (.T.) or false (.F.), or numeric values 0, 1, or 2 in the ControlSource field cause the check box to be selected, cleared, or grayed as the record pointer moves through the table.
Column If the ControlSource is a table field, the user is directly editing the field when editing values in the column. To bind an entire grid to data, set the RecordSource property of the grid.
List box or
combo box
If the ControlSource is a variable, the value the user chooses in the list is stored in the variable. If the ControlSource is a field in a table, the value is stored in the field at the record pointer. If an item in the list matches the value of the field in the table, the item is selected in the list when the record pointer moves through the table.
Option button If the ControlSource is a numeric field, 0 or 1 is written to the field, depending on whether or not the button is chosen.

If the ControlSource is logical, .T. or .F. is written to the field, depending on whether the button is chosen. If the record pointer moves in the table, the value of the option button is updated to reflect the new value in the field.

If the ControlSource of the option button's OptionGroup control (not the option button itself) is a character field, the caption of the option button is stored to the field if the option button is chosen. Note that the control source for an option button (as distinct from an OptionGroup control) cannot be a character field, or Visual FoxPro will report a data type mismatch when the form is run.

Spinner The spinner reflects and writes numeric values to the underlying field or variable.
Text box or
edit box
The value in the table field is displayed in the text box. Changes the user makes to this value are written back to the table. Moving the record pointer affects the Value property of the text box.

Some of the tasks you want to accomplish with controls require having data bound to the control. Other tasks will not. For additional information, see Controls and Objects.

See Also

Using Controls | Control Selection for Particular Tasks | Controls and Objects | Setting the Number of Option Buttons in an Option Button Group | Setting Option Button Properties