Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Set DynamicBackColor by Group
Message
From
10/04/2005 05:13:06
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows 2000 SP4
Network:
Windows NT
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01003119
Message ID:
01003179
Views:
67
>I know this has been probably been asked a zillion times before, but I've been searching and have been unable to find a previous thread.
>
>I want to altnernate the dynamicbackcolor between two colors based on groups of records, not every other record. The grouping can be based on any of several columns depending on how the user is doing a lookup for that instance, and these groups can have varying amounts of records as follows:
>
>Grouped by UPSINO:
>
> UPSINO
> 00001 <---Green
> 00001 <---Green
> 00002 <---White
> 00002 <---White
> 00002 <---White
> 00002 <---White
> 00003 <---Green
> 00003 <---Green
> 00003 <---Green
>
>How do I achieve this through DynamicBackColor?
>
>Thank you.
#DEFINE COLOR_GREEN 0x008000
#DEFINE COLOR_WHITE 0xFFFFFF

CREATE CURSOR mygrid_recordSource (UPSINO C(5))
FOR k=1 TO 10
	FOR j=1 TO 5*RAND()
		INSERT INTO mygrid_recordSource VALUES (TRANSFORM(m.k,"@L 99999"))
	NEXT
NEXT
BROWSE

* Solution 1: 1 STEP: uses RECNO(),SELECT() is SQL command is out of VFP support,
*        but for GROUP BY it is deterministic because VFP allocate the result name
SELECT	UPSINO;
,	IIF(EMPTY(RECNO(SELECT('mygridAttributes'))%2),COLOR_WHITE,COLOR_GREEN) AS BackColor ;
	FROM mygrid_recordSource ; && mygrid.recordSource
GROUP BY 1 ;
INTO CURSOR mygridAttributes

* Solution 2: 2 STEPS: standard and faster if buffering is disabled
SELECT UPSINO,COLOR_GREEN AS BackColor ;
 FROM mygrid_recordSource ; && mygrid.recordSource
 GROUP BY 1 ;
 INTO CURSOR mygridAttributes READWRITE

REPLACE NOOPTIMIZE FOR EMPTY(RECNO()%2) BackColor WITH COLOR_WHITE
BROWSE

* prepare for correlation
INDEX ON UPSINO TAG TG1
SET RELATION TO UPSINO INTO mygridAttributes IN mygrid_recordSource  && mygrid.recordSource

* mygrid.SETALL("DYNAMICBACKCOLOR", "mygridAttributes.BackColor", "COLUMN")

* Check
SELECT mygrid_recordSource 
SET FIELDS GLOBAL
SET FIELDS TO ALL
SET FIELDS TO mygridAttributes.BackColor
BROWSE
SET FIELDS OFF
Previous
Reply
Map
View

Click here to load this message in the networking platform