JavaScript Editor js editor     Web development 

Main Page

The grid is a container object. Just as a form set can contain forms, a grid can contain columns. In addition, the columns contain headers and controls, each with their own sets of properties, events, and methods, giving you a great deal of control over the elements of the grid.

Container Can contain




Headers, controls

The Grid object makes it possible for you to present and manipulate rows and columns of data in a form or page. A particularly useful application of the Grid control is creating one-to-many forms, such as an invoice form.

To add a Grid control to a form

  • In the Form Controls toolbar, choose the Grid button and drag to size in the Form window.

If you do not specify a RecordSource value for the grid and there is a table open in the current work area, the grid will display all the fields in that table.

By default, a grid control is created when you drag a table onto a form.

To create a grid control

You can override the default and create multiple controls corresponding to the default field type mappings specified for each field in the table. For more information, see How to: Create Controls by Dragging and Dropping Fields or Tables.

Setting the Number of Columns in a Grid

One of the first properties you might want to set for the Grid control is the number of columns.

To set the number of columns in a grid

  1. Select the ColumnCount property in the Property and Methods list.

  2. In the Property box, type the number of columns you want.

If the ColumnCount property is set to - 1 (the default), the grid will contain, at run time, as many columns as there are fields in the table associated with the grid.

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.

To see examples of using grids

  1. Run in the Visual FoxPro ...\Samples\Solution directory.

  2. In the tree view, click Controls, and then click Grid.

See Also

JavaScript Editor js editor     Web development