Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Change forecolor in grid
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00613552
Message ID:
00613679
Vues:
14
>>>>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.

Yes, this is correct, the actual algorithm of retrieving the actual values can vary depending on certain conditions.
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform