问题描述
我正在尝试为有几千行的网格着色。我想为它''ledger'样式着色,但我希望颜色在产品#更改时更改 - 而不是每一行。
I'm trying to color a grid which has several thousand rows. I want to color it 'ledger' style but I want the colors to change when the product# changes - not every row.
现在我正在做的是创建一个独特的游标并使用它的recno()检查它的奇数/偶数是这样的:
Right now what im doing is to create a distinct cursor and use its recno() to check if its odd/even like this:
SELECT distinct itemno FROM wind3 INTO CURSOR curw3Colors
SELECT curw3Colors
INDEX on itemno TAG itemno
SELECT wind3
SET RELATION TO itemno INTO curw3colors
* BROWSE FIELDS wind3.cpono,curw3colors.cpono,rec = RECNO(" curw3colors"),col = IIF(MOD(RECNO(" curw3colors)") ,2)= 0,1,2)
SELECT distinct itemno FROM wind3 INTO CURSOR curw3Colors
SELECT curw3Colors
INDEX on itemno TAG itemno
SELECT wind3
SET RELATION TO itemno INTO curw3colors
* BROWSE FIELDS wind3.cpono,curw3colors.cpono,rec=RECNO("curw3colors"),col=IIF(MOD(RECNO("curw3colors"),2)=0,1,2)
this.SetAll(" dynamicbackcolor",'IIF(MOD(RECNO(" curw3colors")) ,2)= 0,RGB(128,128,0),RGB(0,128,128))',"列"))
this.SetAll("dynamicbackcolor",'IIF(MOD(RECNO("curw3colors"),2)=0,RGB(128,128,0),RGB(0,128,128))',"column")
我的问题:
1。有更好的方法吗?
1. Is there a better way to do this?
2。出于某种原因,即使按照预期,我确实得到关系中的itemno的奇数/偶数(通过评论的浏览行验证),我的动态背景颜色出错了。
2. For some reason even though as expected I do get odd/even numbers for the itemno in the relation (Verified by the commented browse line), my dynamicbackcolors are coming up wrong.
任何想法和评论都将不胜感激。
Any ideas and comments would be appreciated.
推荐答案
一旦我必须使用多种依赖于字段值的颜色,我在数据中使用了一个额外的"虚拟"列。这意味着,我这样做我的SELECT / VIEW:
as soon as I have to use multiple colors that depend on field values, I use an additional 'virtual' column in my data. That means, I do my SELECT/VIEW like this:
select *, cast( 0 as i ) as colorsetter
from myTables
where blabla = blabla
但是,这需要第二步,通常是循环,根据多个决定定义新列值。
However, this requires a second step, usually a loop, that defines the new columns value based on multiple decisions.
LOCAL liLoop as Integer
FOR liLoop = 1 to RECCOUNT( [myCursor] )
DO CASE
CASE somefield = hasthisspecialvalue
REPLACE colorsetter WITH 1 IN myCursor
CASE somefield = hasanotherspecialvalue
REPLACE colorsetter WITH 2 IN myCursor
CASE and so on
ENDCASE
ENDFOR
RELEASE liLoop
之后,所有内容都准备好了将所需的代码放在网格或表格中INIT事件:
After that, everything is prepared do place the needed code in the grids or forms INIT Event:
Thisform.grid1.SetAll("DynamicBackColor","Thisform.SetGridColor()")
而且定义ed方法'SetGridColor'如下所示:
And the defined method 'SetGridColor' looks like this:
LOCAL liReturn as Integer
DO CASE
CASE ColorSetter = 1
liReturn = RGB(255,128,128) && LightRed
CASE ColorSetter = 2
liReturn = RGB(255,255,128) && LightYellow
CASE ColorSetter = 3
liReturn = RGB(128,255,255) && LightBlue
CASE ColorSetter = 4
liReturn = RGB(128,255,128) && LightGreen
ENDCASE
RETURN liReturn
HTH
这篇关于每个产品的网格着色#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!