HOWTO: Create a Calculated Column in a Grid
ID: Q138981
|
The information in this article applies to:
-
Microsoft Visual FoxPro for Windows, versions 3.0, 5.0, 6.0
SUMMARY
You can create a calculated column in a grid by entering the calculation in
the ControlSource property for the column.
MORE INFORMATIONStep-by-Step Example
The following steps create a form containing a simple grid. The third
column of the grid is the product of the values in the first two columns.
- Create a new form.
- In Visual FoxPro 3.0, add the Order_Line_Items table from the
Tastrade.dbc database located in the \Vfp\Samples\Mainsamp\Data
directory to the data environment of the form.
-or-
In Visual FoxPro 5.0, add the Order_Line_Items table from the
Tastrade.pjx database located in the \Vfp\Samples\Tastrade directory to
the data environment of the form.
- Drag the table by its title bar from the data environment onto the form
to create a grid.
- Set the Grid.ColumnCount property to 3.
- Set the ControlSource property for each column as follows:
Column1.ControlSource = unit_price
Column2.ControlSource = quantity
Column3.ControlSource = unit_price * quantity
- Save and run the form.
The third column will show the extended price (unit price times quantity)
for each record in the grid.
The grid will not automatically update a field in the table because the
ControlSource is not bound to a specific field. If you need to store the
calculation in a field, add the following code to the AfterRowColChange
event, or to the record validation in the Database Designer:
REPLACE fieldname WITH unit_price * quantity
Additional query words:
Keywords : kbcode kbVFp300 kbVFp500 kbVFp600 FxprgGrid
Version :
Platform :
Issue type : kbhowto
|