有一个表如下,想根据字段A的值变化,用颜色区别。即字段A的值是01、04、06的记录,是一种颜色,字段A的值是03、05的记录,是另一种颜色。请告诉我该怎样做。谢谢!
A B C D
01 zhang 56 789
01 cheng 25 123
01 qing 45 555
03 chen 65 555
03 guan 54 323
04 qiu 45 555
05 cheng 34 333
05 song 43 445
06 li 55 555
...
------解决方案--------------------------------------------------------
grid 控件可以按条件设置每行的前景或背景色
例如设置不同背景色,grid.init 中加几行:
This.SetAll('DynamicBackcolor', ;
[iif(inlist(A,'01','03','05'), rgb(255,0,0), ;
iif(inlist(A,'02','04','06'), rgb(0,0,255), rgb(255,255,255)))], ;
'Column')
------解决方案--------------------------------------------------------
- SQL code
MYFORM = NEWOBJECT("C_FORM")MYFORM.SHOWREAD EVENTSRETURNDEFINE CLASS C_FORM AS FORM AUTOCENTER=.T. CAPTION="表格中颜色显示示例" ADD OBJECT GRID1 AS GRID WITH TOP=((THISFORM.HEIGHT-THISFORM.GRID1.HEIGHT)/2)+20,LEFT=(THISFORM.WIDTH-THISFORM.GRID1.WIDTH)/2 PROCEDURE GRID1.INIT CREATE CURSOR TABNAME (A1 C(2),A2 C(6),A3 N(4),A4 N(4)) INSERT INTO TABNAME VALUES ("01","zhang",56,789) INSERT INTO TABNAME VALUES ("01","cheng",25,123) INSERT INTO TABNAME VALUES ("01","qing",45,555) INSERT INTO TABNAME VALUES ("03","chen",65,555) INSERT INTO TABNAME VALUES ("03","guan",54,323) INSERT INTO TABNAME VALUES ("04","qiu",45,555) INSERT INTO TABNAME VALUES ("05","cheng",34,333) INSERT INTO TABNAME VALUES ("05","song",43,445) INSERT INTO TABNAME VALUES ("06","li",55,555) GO TOP WITH THIS .FONTSIZE=10 .HEADERHEIGHT=28 .RECORDSOURCETYPE = 1 .RECORDSOURCE = "TABNAME" .ROWHEIGHT=24 FOR I = 1 TO .COLUMNCOUNT WITH .COLUMNS(I).HEADER1 .ALIGNMENT=2 ENDWITH ENDFOR ENDWITH *---背景色 THIS.SETALL('DynamicBackColor',"iif(inlist(A1,'03','05'),rgb(255,0,0),iif(inlist(A1,'01','04','06'),rgb(0,0,255),rgb(255,255,255)))",'Column') *---前景色 THIS.SETALL('DynamicForeColor',"iif(inlist(A1,'03','05'),rgb(0,255,0),iif(inlist(A1,'01','04','06'),rgb(255,0,255),rgb(255,255,255)))",'Column') ENDPROC PROCEDURE DESTROY CLEAR EVENTS ENDPROCENDDEFINE
------解决方案--------------------------------------------------------
SELECT *,CAST(A1 AS N(2)) AS AA FROM TABNAME INTO CURSOR TABNAMEA
------解决方案--------------------------------------------------------