Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I color code cells in a grid?

Grids

How can I color code cells in a grid?

by  ChrisRChamberlain  Posted    (Edited  )
If you want to add colour coding to a grid to be able to visually differentiate between records and/or cells, add 2 new fields [color blue](fore_color C(11), back_color C(11))[/color] to the [color blue].RecordSource[/color] table of Grid1.

Add a new form method called [color blue].mGridColours()[/color] and a new form property called [color blue].nRecNo[/color].

In the [color blue].Init[/color] event of Grid1 put:-
[color blue]
THISFORM.nRecNo = RECN([TABLENAME])
THIS.Refresh()
[/color]
In the [color blue].AfterRowColChange()[/color] event of Grid1 put:-
[color blue]
THISFORM.nRecNo = RECN([TABLENAME])
THIS.Refresh()
[/color]
In the [color blue].Column[/color](s) of the grid set [color blue].Sparse = .F.[/color] and [color blue].DynamicCurrentControl = THISFORM.mGridColours()[/color].

In the [color blue].mGridColours()[/color] method put:-
[color blue]
WITH THISFORM.Grid1
[tab]DO CASE
[tab]CASE THISFORM.nRecNo = RECN([TABLENAME])
[tab][tab].Column1.Text1.Forecolor = RGB(255,255,255)
[tab][tab].Column1.Text1.Backcolor = RGB(0,0,128)
[tab]CASE TABLENAME.fore_color = [R/W]
[tab][tab].Column1.Text1.Forecolor = RGB(255,0,0)
[tab][tab].Column1.Text1.Backcolor = RGB(255,255,255)
[tab]CASE TABLENAME.fore_color = [B/W]
[tab][tab].Column1.Text1.Forecolor = RGB(0,255,0)
[tab][tab].Column1.Text1.Backcolor = RGB(255,255,255)
[tab]CASE TABLENAME.fore_color = [G/W]
[tab][tab].Column1.Text1.Forecolor = RGB(0,0,255)
[tab][tab].Column1.Text1.Backcolor = RGB(255,255,255)
[tab]ENDC
ENDW
[/color]
You will find the [color blue].Forecolor[/color] properties of the cells will reflect the value selected by [color blue]TABLENAME.fore_color[/color], with the currently selected record highlighted.

If you want the fields [color blue]TABLENAME.fore_color[/color] and [color blue]TABLENAME.back_color[/color] to determine the colours displayed, then :-
[color blue]
[tab]DO CASE
[tab]CASE ALLT(TABLENAME.fore_color) = [255,255,0]
[tab][tab]lcColor = [.Column1.Text1.Forecolor = RGB(]+ALLT(TABLENAME.fore_color)+[)]
[tab][tab]&lcColor
[tab][tab]lcColor = [.Column1.Text1.Backcolor = RGB(]+ALLT(TABLENAME.back_color)+[)]
[tab][tab]&lcColor
[tab]ENDC[/color]

FAQ184-2483 - answering getting answered.​
Chris [pc2]
[link http://www.pdfcommander.net]PDFcommander[sup]tm[/sup].net[/link]
[link http://www.pdfcommander.net]PDFcommander[sup]tm[/sup].com[/link]

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top