Binding Data with the DataGrid Control

See Also

The DataGrid control binds fields from a recordset and displays the data in a series of rows and columns. The control is automatically populated when you set its dataSource property to a DataSource control.

The data that is displayed in the DataGrid control is always synchronized with the data in the recordset, and vice versa. The cursorType and lockType properties of the recordset determine whether the data dynamically reflects the data in the database, and whether the data in the recordset can be changed.

To bind the DataGrid control to a recordset

  1. Add a DataSource control to your form to retrieve the data. For information on how to do this, see Retrieving a Set of Records.

  2. Add a DataGrid control to the form.

  3. Set the DataGrid control’s dataSource property:

Note that the DataGrid control displays live data in design view. The current record in the recordset is identified by a marker in the grid's corresponding row’s header. To quickly navigate through the rows in the grid, you can add a DataNavigator control to the form.

For information about using the DataGrid control in code, see the DataGrid Control reference topic.

Accessing Column Properties

By setting the DataGrid control's properties in the Properties window, you can quickly configure its appearance and functionality. Each column in the grid also has its own set of properties, which you can access from the grid's properties.

To access the properties of a column

  1. In the Properties window, expand the DataGrid control's columns property. Each column is listed by its index in the grid, which indicates the order in which the column is displayed. (The index of the first column is 0.)

  2. To display the properties of a column, expand its indexed entry.

By default, that DataGrid control contains a column for each field in the underlying recordset, and the columns are ordered according to the fields in the recordset. However, you can easily add, remove, and rearrange columns after the DataGrid control has been created. You can also apply a data format to columns that contain numerical, date, or boolean values.