Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Grid DynamicBackColor trick
Message
From
07/04/2001 09:26:10
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
06/04/2001 11:23:44
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00492054
Message ID:
00493184
Views:
30
>>>If you use the database in the correct order, you can use the recno() odd/even to turn color 1 - color 2. BUT WHAT CAN YOU DO IF YOU HAVE ANOTHER ORDER (THE RECNO() IS NOT IN ORDER ANYMORE)
>>
>>Here's a solution from Cetin,
>>
>>This works faster with tables whose reccount() <= 65000 (for larger tables a cursor could be used instead):
>>
>>
>>
* Grid.init
>>select recno() ;
>>   from (this.recordsource) ;
>>   order by myOrder ;
>>   into array ;
>>   thisform.aOrder  && A form or grid custom array property
>>this.setall("DynamicBackColor",;
>>   "iif(ascan(thisform.aOrder,"+;
>>   "recno())%2=0,rgb(0,255,0),rgb(255,255,0))","Column")
>
>Just to add - another way to speed things up is to simplify any dynamic expression you may be using. They are evaluated for each cell on each refresh of the grid, so I sometimes go as far as to replace the rgb() with its result:
>
>this.setall("DynamicBackColor",;
>   "iif(ascan(thisform.aOrder,"+;
>   "recno())%2=0,"+tran(rgb(0,255,0))+;
>   ","+tran(rgb(255,255,0))+")","Column")
>This way there's two function calls (even if it's such a simple function as rgb() in the expression.
>In the framework we use there was a method call in the dynamicbackcolor expression; the method was just a five-liner, if [expression] - return this.backcolor - else - return thisform.backcolor - endif. Just replacing the method call with an iif() expression containing constants sped it up incredibly. The difference was really visible in the debugger, it was like "oh no it's refreshing again, lemme get some coffee until it finishes" compared to "ok, one, two, here it is".

Good Dragan,
Then you could also make it shorter and increase support count to 65000*2 recs for an array.

-First select into a cursor
-Select only odds or evens into array
-Change expression to something like :
'(ascan(recno())*'+tran(myColor1-myColor2)+tran(myColor1)+')'
No iif() too :)
Say I put only odd ones in array and oddcolor=120000, evencolor=100000
(ascan(recno())*20000+(100000)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform