Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Change forecolor in grid
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00613552
Message ID:
00613676
Views:
9
>>>Good day all,
>>>I want to change the forecolor in a grid based on a criteria. The grid contains 5 column, the fifth column contains numbers between 1 to 5. The color changed based on the number
>>> eg 1 - blue/white
>>> 2 - green/white
>>> 3 - red/white etc.
>>>
>>
>>You would use the DynamicForeColor property of the grid to accomplish this.
>>
>>You could put in the form's init, the following code:
>>
>>MyColor="IIF(Thisform.grdGrid1.Column5.Text1=1,RGB(0,0,255),;
>> IIF(Thisform.grdGrid1.Column5.Text1=2,RGB(0,255,0),;
>> IIF(Thisform.grdGrid1.Column5.Text1=3,RGB(255,0,0),;
>> IIF(Thisform.grdGrid1.Column5.Text1=4,RGB(255,0,0),;
>> IIF(Thisform.grdGrid1.Column5.Text1=5,RGB(255,0,0),RGB(0,0,0))))))"
>>
>>Thisform.grdGrid1.SetAll("DynamicForeColor",MyColor,"Column")
>>
>>The DynamicForeColor is evaluated for each row and not the whole grid at a time.
>>
>>Hope this helps.
>
>IIF approach works well in simple cases. The above IIF contains 270 characters, and as Marcia says it can de optimized with referring to field name value instead of control's value. However, considering that such IIF expressions, depending on number of conditions, may get quite big, and the text properties length is limited with 255 characters it may be recommended to replace the IIF with a user-defined function call, i.e:
>
>Thisform.grdGrid1.Column5.DynamicForeColor = "get_my_color(myAlias.Field5)"
>
>* get_my_color.prg
>LPARAMETER tnValue
>LOCAL lnColor
>DO CASE
> CASE tnValue = 1
> lnColor = RGB(255,0,0)
> CASE tnValue = 2
> lnColor = RGB(0,255,0)
> CASE tnValue = 3
> lnColor = RGB(0,0,255)
> CASE tnValue = 4
> lnColor = RGB(255,255,0)
> CASE tnValue = 5
> lnColor = RGB(0,255,255)
> OTHERWISE
> lnColor = RGB(255,255,255)
>ENDCASE
>RETURN lnColor
>
>It is also easier to maintain a function than a big nested IIF. In any case the big number of conditions may slow down the grid response.

It can also be replaced with a table of Values and colors and the SEEK function or SET RELATION.
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform