Grid, Column, Header
A grid is a "browse-in-a-read" or at least the VFP equivalent. Columns and Headers are the stuff that grids are made of.A grid is a container object. It contains columns. Columns are also containers. They contain headers and controls. Each column has only one header, but can contain as many controls as you like. By default, each column starts out with a single text box.Grids display table, view, or cursor contents. Each row of the grid reflects a single record. When you access the control in a column, it's bound to the appropriate field of the current record (or an expression based on the current record).Grid
Property |
Value |
Purpose |
Numeric |
Contain the number of the column and row that have focus, respectively. Measured in absolute terms from the first row and column of the grid. Uses ColumnOrder for columns, not creation order. |
|
Character |
When the grid is the "many" side of a one-to-many relation, can indicate the name of the index tag by which the table is ordered. (We say "can" because you can also do this using Data Environment properties.) |
|
Numeric |
The number of columns in the grid. Set it to -1 to have one column for each field in the current RecordSource. |
|
Collection |
References to the columns in the grid. |
|
Logical |
Determines whether the grid has a "delete mark" column, allowing the user to click to delete or recall a record. |
|
Numeric |
The color in which the grid lines appear. |
|
Numeric |
Determines whether the grid has horizontal or vertical grid lines, neither or both. |
|
Numeric |
The thickness of the grid lines. |
|
Numeric |
The height of the headers in the grid. |
|
Logical |
Determines whether the contents of the cell with focus are highlighted when you tab into the cell. |
|
Logical |
Determines whether the current cell is highlighted. |
|
Numeric |
New to VFP 7, this determines the width of a box highlighting the current row. Acceptable values are 0–7. HighlightRow must be .T. to use this property. |
|
Numeric |
Contains the ColumnOrder of the leftmost column currently visible in the grid. |
|
Character |
When the grid is the "many" side of a one-to-many relation, can indicate the alias of the "one" table. |
|
Collection |
References to the columns in the grid. |
|
Numeric |
Determines which side of a split grid has the focus. |
|
Logical |
Determines whether the two sides of a split grid are linked. |
|
Numeric |
Determines (in pixels) where the divider for a split grid appears. When 0, the grid isn't split. |
|
Logical |
Determines whether the grid has a column (on the left border) that contains a pointer for the current record. |
|
Character |
The table name, alias or filename of the table or query that provides the data for the grid. |
|
Numeric |
The type of object that provides the data for the grid. |
|
Character |
When the grid is the "many" side of a one-to-many relation, can indicate the expression that links the two tables. |
|
Numeric |
The column and row of the cell with focus, relative to the cell visible in the upper-left corner. |
|
Numeric |
Contains a value indicating whether the row, column, or both changed when moving into the current cell. |
|
Numeric |
The height of the rows in the grid. |
|
Numeric |
Determines what scrollbars, if any, the grid has. |
Event |
Purpose |
Fires after focus has moved to a new cell. |
|
Fires when the user attempts to move focus to a new cell. |
|
Fires when the user uses the scrollbars. |
Method |
Purpose |
Set focus to a particular cell in the grid. |
|
Add and remove columns from the grid. |
|
Scroll the grid in a specified direction. |
|
Return information about the grid element at a specified point. |
Column
Property |
Value |
Purpose |
Logical |
Determines whether the controls in the column are bound to the column's ControlSource or their own. |
|
Numeric |
Determines the display position of the column within the grid. |
|
Numeric |
The number of controls in the column. |
|
Collection |
References to the controls in the column, including the header. |
|
Character |
The name of the control in the column that is presented to the user. |
|
Character |
An expression that evaluates to a legal Alignment value and indicates the alignment for each cell in this column at this time. |
|
Character |
Expressions that evaluate to color values indicating the colors used for this column at this time. Evaluated individually for each cell in the column each time the cell is redrawn. |
|
Character |
An expression that evaluates to the name of one of the column's controls. Indicates which control the user should see. |
|
DynamicFontBold, DynamicFontItalic, DynamicFontName, DynamicFontSize, DynamicFontStrikeThru, DynamicFontUnderline |
Character |
Expressions that evaluate to appropriate font property values. Indicate which font characteristics the column should have at this time. Like other Dynamic... properties, these are evaluated each time the grid is refreshed. |
Character |
Do nothing except in VFP/Mac. |
|
Character |
An expression that evaluates to a valid input mask, indicating the mask to be used for this column at this time. Evaluated each time the grid is refreshed. |
|
Logical |
Determines whether the user can move the column. |
|
Collection |
References to the controls in the column, including the header. |
|
Logical |
Determines whether the user can resize the column. |
|
Logical |
Determines whether the contents of the column are highlighted when the user tabs into it. |
|
Logical |
Determines whether the current control for the column shows all the time or only when the cell has focus. |
Header
Up until VFP 7, headers had no unique or unusual properties, events or methods, just the basic ones shared by many classes. WordWrap is perhaps one of the most heralded enhancements, allowing multi-line grid headers. One of the trickiest issues with grids is figuring out which object in a grid receives events, especially mouse events. The grid receives these events only if nothing it contains is able to. If you click in a control of a column, the control's Click is executed. If you click on the header of a column, the header's Click fires. To fire the grid's Click, you have to click on a row after the last record, or on the record mark or delete mark.
VFP 7 Service Pack 1 fixes a bug introduced in VFP 7, where the Click and other events are called only if the grid's RecordSource contains records. |
Example |
* Set up a grid as the child side of the relation between * the TasTrade Orders and Order_Line_Items tables. * Assume both tables are in the Data Environment, but that * the relation between them has been removed. Usually, you * wouldn't do it this way - you'd use the relation in the DE. * Set these grid properties as shown: RecordSource = "Order_Line_Items" ChildOrder = "Order_Id" LinkMaster = "Orders" RelationalExpr = "Order_Id" * Now let's put only the columns we want to see: ColumnCount = 3 * Now switch to column properties. * For column1.header1: Caption = "Product Id" * For column1: ControlSource = "Order_Line_Items.Product_Id" * For column2.header1: Caption = "Unit Price" * For column2: ControlSource = "Order_Line_Items.Unit_Price" * For column3.header1: Caption = "Quantity" * For column3: ControlSource = "Order_Line_Items.Quantity" * Now set the column up to use blue for any item where quantity * is more than 10. For column3: DynamicForeColor = "IIF(Order_Line_Items.Quantity>10, ; RGB(0,0,255),RGB(0,0,0))" * You'll want to do more cosmetic stuff like resizing the * columns and so forth. |