Grid

Available only in graphical environments, the grid control is a two-dimensional table of data fields. Each element of this table, called a cell, can hold text, a bitmap, or both. Grids are relatively complex controls with many properties that you can use to customize their appearance and behavior.

BKBEBECTRL09-low.gif

Grids are organized into rows, columns, and records. In a grid, a row is a grouping of cells that appear on one line in the control. A record is one or more rows that are treated as a logical unit. A column identifies a particular cell in a record. By default, a record occupies one row in a grid, but you can arrange for a record to wrap around to the next row when it passes the right edge of the grid. When this occurs, a record occupies more than one row in the grid. You might want to construct a grid like this when you want to see many fields in a data record at once. Alternatively, you can have the grid use scroll bars to access cells past the right edge of the control. Column, row, and record numbers all start at 1.

Grids come in two formats: with horizontal scrolling and without. When you opt for horizontal scrolling, each record may occupy only one row in the grid. Grids with horizontal scrolling appear much like a spreadsheet. Without horizontal scrolling, a record may occupy more than one row. In either case, vertical scroll bars appear automatically when needed.

The grid operates in two different modes: navigate mode and entry mode. While the grid is in navigate mode, the arrow keys move the cursor around the grid. This mode is the default. The grid shifts to entry mode when the user starts to modify data. In this mode, the arrow keys are used to edit the current cell's data. When the user finishes a cell, the grid returns to navigate mode.

The exact set of keys understood by the grid depends on the host system. Under Windows, the following keys are used in navigate mode:

Up/Down arrow Moves the cursor to the same column in the previous/next record
Left/Right arrow Moves the cursor to the previous/next column in the record
Home Moves to the first column in the record
Ctrl+Home Moves to the first column of the first record
Page up/Page down Moves the cursor up/down one page
Shift+Enter Moves the cursor to the first column of the next record
Tab

(with USE-TAB)

Moves the cursor right, wrapping to the next record when at the last cell in the record
Backtab

(with USE-TAB)

Moves the cursor left, wrapping to the previous record when at the first cell in the record
End Moves to the last column in the record
Ctrl+End Moves to the first column in the last record
Enter Shifts to entry mode for the current cell; highlights the contents for editing
Any printable character Shifts to entry mode for the current cell; overwrites the contents with the character

When the grid is in entry mode, the user types into an entry field control. All of the editing keys usable by an entry field are usable here. The user leaves entry mode by typing Enter or Tab/Backtab, or by clicking another cell with the mouse.

Clicking a mouse on a cell moves the cursor to that cell. Clicking the selected cell shifts to entry mode. So double-clicking any cell has the effect of modifying that cell's contents. The first click moves the cursor and the second click shifts modes.

You should note that the Property window Value cell for the Row-Dividers property accepts only a single digit. You cannot enter multiple values in the workbench for Row-Dividers.

Paged Grid

Sometimes you may want to use a grid control to view a large number of records. When this is the case, a normal grid is impractical. Just loading all the records into the grid could take an excessive amount of time. To handle this case, the grid supports a Paged style. When you use this style, the grid holds only as many records as can be seen on the screen. This is called a page of data. Four buttons that get the next/previous record and the next/previous page of records replace the vertical scroll bar. When the user clicks one of these buttons, the control sends a message to the program asking for the appropriate data. The program itself must supply the needed data. This data typically comes from an indexed file, and the appropriate program logic is to do one or more READ NEXT/PREVIOUS statements to retrieve the data.

The grid control communicates requests for more data via events. More information about grid events can be found in Events Reference.

Paged grids never hold more data than they can display. When adding a record to a full page, the control deletes the top non-heading record when a record is added to the end of the grid. This causes the grid's contents to scroll upwards. When adding a record to any other position, the last record in the grid is deleted. This causes all records after the one being added to scroll downwards.

Note that the current cell is not changed when the grid is paged. In other words, if the grid's cursor is at row 2, column 3, it is at row 2, column 3 after the user clicks the "next record" button. This action effectively moves the cursor to a new record, even though its physical location has not changed. Unlike other forms of cursor movement, this does not generate any additional events. If you are performing special actions when the cursor enters a new cell (for example, displaying related information outside of the grid), then you should perform these actions in response to paging events as well as cursor-movement events.