Share via


DynamicBackColor, DynamicForeColor Properties

Specifies the background and foreground colors of a Column object. Available at design time; read/write at run time.

Column.DynamicBackColor [= "cExpression"]
Column.DynamicForeColor [= "cExpression"]

Return Value

  • cExpression
    Specifies a character expression evaluates at run time to a single color value. The color value is reevaluated at run time whenever the Grid control is refreshed.

Remarks

Applies To: Column Object

Note

The Grid AutoFit method might not resize adequately to display the entire contents of a column if you use these properties.

You can use the DynamicBackColor and DynamicForeColor properties to create special effects, such as displaying the odd-numbered rows in green and the even-numbered rows in gray.

Example

The following example uses the DynamicBackColor property and the SetAll method to specify the background colors for the records in a Grid control. If the number of a record displayed in the grid is even, the record's DynamicBackColor is white; otherwise, DynamicBackColor is green.

A Grid control is placed on a form, and the customer table is opened and its contents displayed in the Grid. The Caption property is used to specify a different header caption (Customer ID) for the CUST_ID field. A command button is placed on the form to close the form.

CLOSE ALL  && Close tables and databases
OPEN DATABASE (HOME(2) + 'Data\testdata')

USE customer  IN 0  && Opens Customer table

frmMyForm = CREATEOBJECT('Form')  && Create a Form
frmMyForm.Closable = .f.  && Disable the Control menu box 

frmMyForm.AddObject('cmdCommand1','cmdMyCmdBtn')  && Add Command button
frmMyForm.AddObject('grdGrid1','Grid')  && Add Grid control

frmMyForm.grdGrid1.Left = 25  && Adjust Grid position

frmMyForm.grdGrid1.SetAll("DynamicBackColor", ;
   "IIF(MOD(RECNO( ), 2)=0, RGB(255,255,255) ;
   , RGB(0,255,0))", "Column")  && Alternate white and green records

frmMyForm.grdGrid1.Visible = .T.  && Grid control visible
frmMyForm.cmdCommand1.Visible =.T.  && "Quit" Command button visible
frmMyForm.grdGrid1.Column1.Header1.Caption = 'Customer ID'

frmMyForm.SHOW  && Display the form
READ EVENTS  && Start event processing

DEFINE CLASS cmdMyCmdBtn AS CommandButton  && Create Command button
   Caption = '\<Quit'  && Caption on the Command button
   Cancel = .T.  && Default Cancel Command button (Esc)
   Left = 125  && Command button column
   Top = 210  && Command button row
   Height = 25  && Command button height

   PROCEDURE Click
      CLEAR EVENTS  && Stop event processing, close Form
      CLOSE ALL  && Close table and database
ENDDEFINE

See Also

Reference

BackColor, ForeColor Properties

Other Resources

Properties (Visual FoxPro)

Language Reference (Visual FoxPro)