Standard and Data-Aware Grids

There are two basic modes for a grid control: standard and data-aware.

Standard Grids

Standard grids require more Visual PRO/5 coding than data-aware grids but are more flexible. Standard grids are populated and maintained by the application program. They are presentation structures, not data storage structures. It is the responsibility of the application program to manage the data that is to be displayed in a grid and to keep track of changes in the grid if editing is allowed (see the sample code for Start Edit - Grid SENDMSG() Function 31 for an example).

Scrolling in a standard grid prompts it to be redrawn continuously. Column headings are cached, but there is no guarantee that row headings and grid cells will be cached. Therefore, the main grid and the row heading grids may need data from the application when they are redrawn. Grid controls request data by sending Notify event 22 to the application. It is imperative that an event loop managing a standard grid checks for Notify event 22 from the main grid control and the row header grid, if present, and respond to them. Otherwise, blank cells and headers may appear in the grid (see the Standard Grid Tutorial 1: Display-Only Grid and Standard Grid Tutorial 2: User-Modifiable Grid for examples of how this can be done).

There are two ways to put display data in standard grid cells:

To set up a program to capture data entered by a user in a grid (see the sample code for Start Edit - Grid SENDMSG() Function 31 for more specifics):

  1. Set up a data structure to hold the data to be displayed in the grid.

  2. Code the event loop to respond to Notify event 22 by displaying data in cells with Draw Cell - Grid SENDMSG() Function 54.

  3. Code the event loop to respond to some event that will initiate editing in a grid cell. Left or right mouse button clicks, for example, can be detected with Notify events. When the event is detected, put the cell in edit mode with Start Edit - GRID SENDMSG() Function 31.

  4. Code the event loop to respond to Notify event 7, which is fired when the user finishes editing.

  5. Retrieve the edited value withGet Edit Text - Grid SENDMSG() Function 34.

  6. Store the text in the data structure. It is generally not necessary to redisplay the data entered by the user unless a validation routine changes the data after the user has entered it.

Data-Aware Grids

For BBj-specific information, see General Grid Enhancements in BBj.

Data-aware grids display data from files and handle file I/O automatically. Data-aware grids require less Visual PRO/5 coding than standard grids but are not as flexible. Data-aware grids must be attached to an MKEYED, Visual PRO/5 SELECT, or SQL SELECT channel. Only one channel can be handled by a grid control at one time. A data-aware grid can be used for viewing a file, or it can be programmed to allow inserting, deleting, and updating, if an MKEYED or Visual PRO/5 SELECT channel is used. The grid control handles changes to the underlying file.

Validation Issues with Data-Aware Grids

Since data-aware grids write records to the underlying data file as soon as the user moves the highlight off the edited row, it is impossible to validate all data before it is written. For this reason, only temporary files should be edited with data-aware grids in production environments. Note that data-aware grids are read-only unless code is specifically written to allow editing.