Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Questions about Dynamic Color in Grids
Message
 
To
02/11/2004 05:55:21
Aaron K. Y. Chu
Health & Care Co. Ltd.
Hong Kong, Hong Kong
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
MySQL
Miscellaneous
Thread ID:
00956908
Message ID:
00957171
Views:
14
>Hi All,
>
>I would like to ask about the dynamic color in a grid to display a series of records which are sorted according to the date of entries. I want to display the records with same date in same color.
>
>How can I do that?
>
>
>Best regards,
>Aaron

Aaron,

How about mapping the value of the date to a color value?

(I don't know what kind of date range you are using, but let's assume you are looking at it within a month)
First you create a function in a prg or a method in a form, let's say it is called MapColor:
FUNCTION MapColor
LPARAMETERS lpnDay
*lpnDay is the day of the month as return by DAY(DATE())
DO CASE 
	CASE m.lpnDay = 1
		RETURN RGB(255,255,255)
	CASE m.lpnDay = 2
		RETURN RGB(128,255,255)
	CASE m.lpnDay = 3
		RETURN RGB(255,0,0)
	CASE m.lpnDay = 4
		RETURN RGB(255,255,128)
	CASE m.lpnDay = 5
		RETURN RGB(0,0,255)
	CASE m.lpnDay = 6
		RETURN RGB(0,255,0)
	CASE m.lpnDay = 7
		RETURN RGB(255,0,255)
	CASE m.lpnDay = 8
		RETURN RGB(0,255,255)
	CASE m.lpnDay = 9
		RETURN RGB(255,255,0)
*.... and so on 
	CASE m.lpnDay = 31
		RETURN RGB(255,255,0)
	OTHERWISE
ENDCASE 
ENDFUNC && MapColor 
Once you have this method, you can use it to change your grid's DynamicBackColor as like this:
*1. If defined in a prg
set procedure to myprg.prg
this.mygrid.column1.DynamicBackColor = "MapColor(DAY(mydatefield))"

*2. If defined in the form where your grid is contained
this.mygrid.column1.DynamicBackColor = "thisform.MapColor(DAY(mydatefield))"

This way all the same day would be grouped by the same color. You can expand the idea if the date range is beyond a month. You can difine the colors like this:
do case
   case lnMonth=1
     do case
        case lnDay=1
             return rgb(255,255,255)
     * and so on 
     endcase 
   * and so on 
endcase 
The advantage of mapping color like this is that you are in control of the selection of the colors and you can provide the users a legend of the colors used that represent the days of the month.

Hope this solves your dilemma,
Dawa Tsering


"Do not let any unwholesome talk come out of your mouths,
but only what is helpful for building others up according to their needs,
that it may benefit those who listen."

- Ephesians 4:29-30 NIV

Dare to Question -- Care to Answer

Time is like water in a sponge, as long as you are willing you can always squeeze some.

--Lu Xun, Father of Modern Chinese Literature

Previous
Reply
Map
View

Click here to load this message in the networking platform