The information in this article applies to:
- Microsoft Visual FoxPro for Windows, versions 3.0 and 3.0b
SUMMARY
This article shows by example how to maintain the changed ForeColor of a
grid cell upon selecting a cell that has had its default forecolor changed
(based on criteria of the data) to something other than the default.
MORE INFORMATION
The following example shows how to have a selected cell in a grid retain
its changed ForeColor upon selecting the cell, instead of the cell changing
its color back to the default color.
Step-by-Step Example
- Create a new form and add the Customer table (located in Samples\Data)
to the Data Environment. Place a grid on the form by dragging the
Customer table from the Data Environment.
- Change the Grid1 ColumnCount property to 2.
- Ensure that the Grid1 RecordSource property is Customer.
- Ensure that the RecordSourceType property is 1 - Alias.
- Change the Grid1 Column1 ControlSource property to customer.cust_id.
- Change the Grid1 Column2 ControlSource property to customer.country.
- Place the following code in Grid1 Column1 DynamicForeColor method:
"IIF(customer.country='Germany',255,0)" && use the quotation marks
NOTE: The previous line changes the ForeColor to Red if the country is
Germany, otherwise it is Black. (There should be an equal (=) sign
in front of this statement in the property sheet dialog line.
- Place the following code in the Grid1 Column1 Text1 GotFocus event:
This.SelectedForeColor=IIF(customer.country='Germany',255,0)
NOTE: The previous line retains the ForeColor of the cell upon
selection.
- Save and run the Form.
Using the up and down arrow keys, scroll through the grid and observe that
the records having Germany in the Country column maintain red as the cells
are selected - instead of changing to black. Remove the line of code in
Grid1.Column1.Text1.GotFocus event, run the form, and observe that the
selected Germany cell changes to black upon selection.
|