Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Alternate color columns in a Grid?
Message
From
06/11/2004 05:12:38
 
 
To
05/11/2004 16:19:05
Calvin Smith
Wayne Reaves Computer Systems
Macon, Georgia, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00958685
Message ID:
00958808
Views:
19
>I am using these commands to color the current row and alternate the color in 1 column of a data grid:
>
>with thisform.grid1
>.nRecNo=recno('pdfs') .setall('dynamicbackcolor','iif(recno(this.recordsource)=this.nRecNO,rgb(192,192,192),rgb(255,255,255))','column')
>.column4.dynamicbackcolor='iif(mod(thisform.grid1.activerow,2)=1,rgb(255,255,0),rgb(255,128,192))'
>.SetFocus()
>endwith
>
>The reason I am using Thisform.grid1.activerow to set the dynamicbackcolor rather than the .nRecNo property is that this data is not in recno order and cannot easily be made to be in recno order.
>
>All works well until the user clicks to do a page down on the scroll bar. Column4 then becomes 1 color and stays so until the user either clicks on the grid or does a key event to move the record pointer in the grid.
>
>I have put the .column4.dynamicbackcolor line of code in the grids scrolled event, but no joy.
>
>Any suggestions?

Do not to use activerow,
- everytime you call it, VFP do a COUNT command.
- when the grid it is repainted and the grid it is not active, activerow it is 0.

Add a field iRow
* for fill it the correct command it is 
REPLACE ALL iPos with _TALLY && +1 if you want base 1 order
* BUT REPLACE have a bug and _TALLY return RECNO()
* then you have to lost 50% speed with next lines
iPos=0
SCAN
   REPLACE iPos with m.iPos+1
   STORE iPos TO iPos
ENDSCAN
Another solution it is to use a hash table:
DIMENSION thisform.grid.aRows[RECCOUNT()]
iPos=0
SCAN
   STORE m.iPos+1 TO iPos,aRows[RECNO()]
ENDSCAN
='iif(mod(this.aRows[RECNO()],2)=1,rgb(255,255,0),rgb(255,128,192))'
Of course if you use this for odd/even backcolor only, you can put the color into the array
directly:
* PROCE gridBackColorSet
SELECT (m.this.RecordSource)
ADDPROP(m.this,"aBackColor[RECCOUNT()]")
iPos=0
SCAN
   STORE m.iPos+1 TO iPos,
   this.aBackColor[RECNO()]=IIF(empty(m.iPos%2),rgb(255,128,192),rgb(255,255,0))
ENDSCAN
....='this.aBackColor[RECNO()]'
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform