Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Displaying DynamicForeColor in grid
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00613829
Message ID:
00613835
Vues:
10
>Hi All,
>
>
>I have task to display different colors of the record in grid depending on following criteria:
>
>* RGB(0,128,0) green
>* RGB(0,0,255) blue
>* RGB(255,128,0) orange
>* RGB(255,255,0) red
>pexp is the field name in my table
>
>Now this is working but is not displaying RED color for the records where date of pexp is > then todays date
>
>this.SetAll("DynamicForeColor",;
>"IIF(hour(pexp)-hour(datetime())>3,RGB(0,128,0),;
>iif(hour(pexp)-hour(datetime())=3, RGB(0,0,255),;
>iif(hour(pexp)-hour(datetime())=2, RGB(255,128,0),;
>iif(hour(pexp)-hour(datetime())<=1, RGB(255,0,0),RGB(200,0,0)))))","Column")
>
>
>..so my expresion should be like
>
>*thisform.aa = hour(datetime())
>
>*!* WITH THISFORM
>*!* this.SetAll("DynamicForeColor",;
>*!* "IIF(hour(pexp)-.aa>3 and ttod(datetime())<=ttod(pexp),RGB(0,128,0),;
>*!* iif(hour(pexp)-.aa=3 and and ttod(datetime())<=ttod(pexp), RGB(0,0,255),;
>*!* iif(hour(pexp)-.aa=2 and ttod(datetime())<=ttod(pexp), RGB(255,128,0),;
>*!* iif(hour(pexp)-.aa<=1 and ttod(datetime())<=ttod(pexp), RGB(255,0,0),RGB(200,0,0)))))","Column")
>*!* ENDWITH
>
>
>..but unfortunataly is longer the 255 characters.
>
>Can anybody see another way of displaying the proper colors:
>Text color criteria is:
>if Expiry time >= 3 hours GREEN
>if Expiry time = 3 hours BLUE
>if Expiry time = 2 hours ORANGE
>if Expiry time <= 1 hours RED and pexp is < todays date
>
>Please help.
>
>Thanks
>
>Dejan

This is easy, if instead of IIF you call user-defined function. For example:

Thisform.grdGrid1.SetAll("DynamicForeColor", "get_my_color(myvalue)", "Column"
* 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
The main trick here is a UDF call in Dynamic... property, which returns the appropriate color. The exact algorithm in UDF does not matter much. Depending on circumstances you might use DO CASE (as in above sample), or use an array property, or get the colors from the some lookup table, etc.

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.
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