INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Grids

How can I color code cells in a grid? by ChrisRChamberlain
Posted: 5 Apr 01 (Edited 9 May 06)

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 (fore_color C(11), back_color C(11)) to the .RecordSource table of Grid1.

Add a new form method called .mGridColours() and a new form property called .nRecNo.

In the .Init event of Grid1 put:-

THISFORM.nRecNo = RECN([TABLENAME])
THIS.Refresh()

In the .AfterRowColChange() event of Grid1 put:-

THISFORM.nRecNo = RECN([TABLENAME])
THIS.Refresh()

In the .Column(s) of the grid set .Sparse = .F. and .DynamicCurrentControl = THISFORM.mGridColours().

In the .mGridColours() method put:-

WITH THISFORM.Grid1
    DO CASE
    CASE THISFORM.nRecNo = RECN([TABLENAME])
        .Column1.Text1.Forecolor = RGB(255,255,255)
        .Column1.Text1.Backcolor = RGB(0,0,128)
    CASE TABLENAME.fore_color = [R/W]
        .Column1.Text1.Forecolor = RGB(255,0,0)
        .Column1.Text1.Backcolor = RGB(255,255,255)
    CASE TABLENAME.fore_color = [B/W]
        .Column1.Text1.Forecolor = RGB(0,255,0)
        .Column1.Text1.Backcolor = RGB(255,255,255)
    CASE TABLENAME.fore_color = [G/W]
        .Column1.Text1.Forecolor = RGB(0,0,255)
        .Column1.Text1.Backcolor = RGB(255,255,255)
    ENDC    
ENDW

You will find the .Forecolor properties of the cells will reflect the value selected by TABLENAME.fore_color, with the currently selected record highlighted.

If you want the fields TABLENAME.fore_color and TABLENAME.back_color to determine the colours displayed, then :-

    DO CASE
    CASE ALLT(TABLENAME.fore_color) = [255,255,0]
        lcColor = [.Column1.Text1.Forecolor = RGB(]+ALLT(TABLENAME.fore_color)+[)]
        &lcColor
        lcColor = [.Column1.Text1.Backcolor = RGB(]+ALLT(TABLENAME.back_color)+[)]
        &lcColor
    ENDC


FAQ184-2483 - answering getting answered.
Chris pc2
PDFcommandertm.net
PDFcommandertm.com


Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close