DynamicBackColor
A customer asked about how to change the colors in a grid dynamically. The code below changes the 3rd column’s backcolor if the row is selected. You can change the code to be based on a value in the row too.
PUBLIC ox
USE (SET("Resource",1)) AGAIN
ox=CREATEOBJECT("form")
ox.addobject("gr","grid")
ox.width=500
ox.gr.width=500
ox.gr.visible=1
ox.visible=1
ox.gr.column1.DynamicBackColor="iif(MOD(RECNO(),2)=0,RGB(255,0,0),RGB(255,255,255))"
ox.gr.column2.text1.SelectedBackColor=RGB(255,0,0)
ox.gr.column3.DynamicBackColor="iif(ox.gr.ActiveRow=RECNO(),RGB(255,0,0),RGB(255,255,255))"
Comments
- Anonymous
October 05, 2005
Note that a complex DynamicBackColor expression together with a fully loaded grid will make the foxpro frame takes a while to refresh when switching from the debugger frame in stepping mode. - Anonymous
September 26, 2007
This is a great example of dynamic back color, but the example fails to work on appended records because recno() returns -1.