Partager via


Setting the Source of the Data Displayed in the Grid

You can set the data source for the grid and for each column individually.

To set the data source for a grid

  1. Select the grid, and then click the RecordSourceType property in the Properties window.
  2. Set the RecordSourceType property to 0 - Table, if you want Visual FoxPro to open the table for you, or 1 - Alias if you want the grid to be populated with the fields in a table that is already open.
  3. Click the RecordSource property in the Properties window.
  4. Type the name of the alias or table to serve as the data source for the grid.

If you want to specify particular fields to be displayed in particular columns, you also can set the data source for a column.

To set the data source for a column

  1. Select the column, and then click the ControlSource property in the Properties window.

  2. Type the name of the alias or table and the field to serve as the source for the values displayed in the column. For example, you can type:

    Orders.order_id
    

Adding Records to a Grid

You can make it possible for users to add new records to a table displayed in a grid by setting the AllowAddNew property of the grid to true (.T.). When the AllowAddNew property is set to true, new records are added to the table when the last record is selected and the user presses the DOWN ARROW key.

If you want more control over when a user adds new records to a table, you can set the AllowAddNew property to false (.F.), the default, and use the APPEND BLANK or INSERT commands to add new records.

See Also

Manually Adjusting Grid Display at Design Time | Setting Up a One-to-Many Form Using the Grid Control | Displaying Controls in Grid Columns | Using Controls | Controls and Objects