FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour xBrowse color a cell ( again )
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
xBrowse color a cell ( again )
Posted: Mon Sep 13, 2010 07:30 PM
To All

In searching the forum .. I am having difficulty trying to find the code that will be able to change a cell color based on the data in the cell .. I can easily change the entire line based on a value in a row .. but am having difficulties as in this example

column 7 can contain the 3 values 'GREEN', 'YELLOW' or 'RED' .. I want to be able to just color (nROW, 7 ) 'last status' with the correct color .. white\green, black\yellow or white\red. Here is my code where I am struggling .. I am migrating from the standard FWH list box to xbrowse :

Code (fw): Select all Collapse
nWd := GetSysMetrics(0) * .70 //.60
nHt := GetSysMetrics(1) * .85
DEFINE ICON oICO RESOURCE "SCANNER"

DEFINE WINDOW oWnd1                        ;
      FROM 1,1 to nHT, nWD PIXEL           ;
      TITLE cTITLE                         ;
      MENU ProjMenu(oRsProj, oWndMdi)      ;
      ICON oICO                            ;
      NOMINIMIZE                           ;
      NOZOOM                               ;
      MDICHILD

@ 0, 0 xBROWSE oBrw of oWnd1     ;
       RECORDSET oRsProj         ;
       COLUMNS "PROJNAME",       ;
               "descrip",        ;
               "reporting",      ;
               "projmgr",        ;
               "start_date",     ;
               "end_date",       ;
               "est_budget",     ;
               "frequency",      ;
               "row_color"       ;
       COLSIZES 130,183,30,85,85,85,85,90,90  ;
       HEADERS "Proj Name",                ;
               "Description",              ;
               "CRpt",                     ;
               "ProjMgr",                  ;
               "Orig Start Dt",            ;
               "Orig End Date",            ;
               "Orig Est Budget",          ;
               "Frequency",                ;
               "Last Status"               ;
        AUTOSORT AUTOCOLS LINES CELL

        oWnd1:oClient := oBrw
        oBrw:bLDblClick := { |nRow,nCol | _ProjView( "V", oRsProj,"","" ) }
      *  oBrw:bClrStd := {|| {CLR_BLACK, if( oRsProj:Fields("active"):Value = 'Y', RGB(179,203,204), CLR_WHITE ) } }

        AEval( oBrw:aCols, { |o| SetClrBlock( o, oRsProj ) } )

       // paint the row colors active and status column  //
     *  obrw:nClrText      := { |nCOL| SelColorF( nCOL, oRsProj:Fields("row_color"):Value, oRsProj:Fields("active"):Value, "F" ) }
     *  oBrw:nClrPane      := { |nCOL| SelColorB( nCOL, oRsProj:Fields("row_color"):Value, oRsProj:Fields("active"):Value, "B" ) }
    //   oBrw:nClrForeFocus = { |nCOL| SelColorH( nCOL, oRsProj:Fields("row_color"):Value, oRsProj:Fields("active"):Value, "F" ) }
    *   oBrw:nClrBackFocus := { |nCOL| SelColorH( nCOL, oRsProj:Fields("row_color"):Value, oRsProj:Fields("active"):Value, "B" ) }

      *  oBrw:aCols[ 9]:bClrStd := {|| { IF( ALLTRIM(oRsProj:Fields("row_color"):Value) = 'YELLOW', CLR_YELLOW, CLR_HGREEN), CLR_WHITE } }
       * oBrw:bClrSel:={ || { nTextClr, nBackClr } }
         oBrw:CreateFromCode()    // recommendation from daniel

ACTIVATE WINDOW oWND1 ;
         ON INIT( IF( lFROMLINK = .T., (_ProjView( "V", oRsProj,"", lFROMLINK  )), ),( oBrw:SetFocus(), .F. ));
         VALID ( IIF( !lOK, _ProjClose(.T.), .F. ))

RETURN( .T. )

//------------------------
static function SetClrBlock( oCol, oRsProj )

*local nCol    := oCol:nCreationOrder
*local oBrw    := oCol:oBrw
LOCAL cSTATUS,cACTIVE


IF EMPTY(oRsProj:Fields("row_color"):Value)
   cSTATUS := "NO STATUS"
ELSE
   cSTATUS := alltrim( oRsProj:Fields("row_color"):Value)
ENDIF

IF EMPTY(oRsProj:Fields("active"):Value)
   cACTIVE := "*"
ELSE
   cACTIVE := oRsProj:Fields("active"):Value
ENDIF


*oBrw:aCols[ 9]:bClrStd := {|| { IF( ALLTRIM(oRsProj:Fields("row_color"):Value) = 'YELLOW', CLR_YELLOW, CLR_HGREEN), CLR_WHITE } }

DO CASE
*CASE nCOL < 9

CASE cSTATUS = "YELLOW"
      oBrw:aCols[ 9]:bClrStd := {||  { CLR_WHITE, CLR_YELLOW } }

 *  oBrow:bClrStd := {|| {CLR_BLACK, if( cACTIVE = 'Y', RGB(179,203,204), CLR_WHITE ) } }
   /*
   IF cACTIVE = 'N'
      oCOL:bClrStd := { || { CLR_WHITE, RGB(179,203,204)}}
   *   nCOLOR := RGB(179,203,204)     // light blue
   ELSE
      oCOL:bClrStd := { || { CLR_BLACK, CLR_WHITE }}
   ENDIF
  */
*CASE nCOL = 9 .and. cSTATUS = "GREEN"
*     oCOL:bClrStd := { || { CLR_WHITE, CLR_HGREEN }}
*oBrw:aCols[ 7]:bClrStd := {|| { IIF( oRsPro:Fields("PRO_PRE"):Value  > 10000, CLR_HRED, CLR_HBLUE), CLR_GRAY } }
*CASE nCOL = 9 .and. cSTATUS = "YELLOW"
*     oCOL:bClrStd := { || { CLR_WHITE, CLR_YELLOW }}

*CASE nCOL = 9 .and. cSTATUS = "RED"
*     oCOL:bClrStd := { || { CLR_WHITE, CLR_HRED }}

ENDCASE

return nil


//-----------------------------------------------
Static Func SelColorB( nCOL, cCOLOR, cACTIVE, cTYPE )

LOCAL nCOLOR := CLR_WHITE

// background for all cells

msginfo( ncol )

DO CASE
CASE nCOL < 9
   IF cACTIVE = 'Y'
      nCOLOR := CLR_WHITE
   ELSE
      nCOLOR := RGB(179,203,204)     // light blue
   ENDIF

CASE nCOL = 9 .and. cCOLOR = "GREEN" .and. cTYPE = "B"
     nCOLOR := CLR_HGREEN

CASE nCOL = 9 .and. cCOLOR = "YELLOW".and. cTYPE = "B"
     nCOLOR := CLR_YELLOW

CASE nCOL = 9 .and. cCOLOR = "RED"   .and. cTYPE = "B"
     nCOLOR := CLR_HRED

ENDCASE

RETURN( nCOLOR )

//--------------------
Static Func SelColorF( nCOL, cCOLOR, cACTIVE, cTYPE )

LOCAL nCOLOR := CLR_BLACK

// forground for all cells

IF EMPTY(nCOL) .or. nCOL = NIL
   nCOL := 8
ENDIF

DO CASE
CASE nCOL < 9
     IF cACTIVE = 'Y'
        nCOLOR := CLR_BLACK
     ELSE
        nCOLOR := CLR_BLACK // RGB(255,0,0 )        // red
     ENDIF

CASE nCOL = 9 .and. cCOLOR = "GREEN" .and. cTYPE = "F"
     nCOLOR := CLR_BLACK

CASE nCOL = 9 .and. cCOLOR = "YELLOW".and. cTYPE = "F"
     nCOLOR := CLR_BLACK

CASE nCOL = 9 .and. cCOLOR = "RED"   .and. cTYPE = "F"
     nCOLOR := CLR_BLACK

ENDCASE

RETURN( nCOLOR )

//-----------------------------------------------
Static Func SelColorH( nCOL, cCOLOR, cACTIVE, cTYPE )

// background for hi-lite bar

LOCAL nCOLOR := CLR_HGRAY

msginfo( ncol )
msginfo( "selcolorh")

return(ncolor )


DO CASE
CASE nCOL < 9
   IF cACTIVE = 'Y'
      nCOLOR := rgb( 122,122,122 ) //CLR_HGRAY
   ELSE
      nCOLOR := RGB(179,203,204)     // light blue
   ENDIF

CASE nCOL = 9 .and. cCOLOR = "GREEN" .and. cTYPE = "B"
     nCOLOR := CLR_HGREEN

CASE nCOL = 9 .and. cCOLOR = "YELLOW".and. cTYPE = "B"
     nCOLOR := CLR_YELLOW

CASE nCOL = 9 .and. cCOLOR = "RED"   .and. cTYPE = "B"
     nCOLOR := CLR_HRED

ENDCASE

RETURN( nCOLOR )



Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xBrowse color a cell ( again )
Posted: Tue Sep 14, 2010 12:00 AM
Please remove all your code about colors and add this line:
Code (fw): Select all Collapse
oBrw:bClrStd := {|| {CLR_BLACK, if( oBrw:oRs:Fields("active"):Value = 'Y', RGB(179,203,204), CLR_WHITE ) } }

oBrw:oCol( "last status" ):bClrStd := ;
   { || HB_Decode( AllTrim( oBrw:oCol("last status"):value ), ;
       "GREEN", { CLR_WHITE, CLR_GREEN }, ;
       "YELLOW", { CLR_BLACK, CLR_YELLOW }, ;
       { CLR_WHITE, CLR_RED } ) }


Also, I advise you to avoid coding by referring to columns with numbers as in oBrw:aCols[9].

In XBrowse, the user can move the position of columns according to his convenience, need and taste. At runtime, oBrw:aCols[ 9 ] need not be the nineth column we created initially and that may refer to some other column.
Regards



G. N. Rao.

Hyderabad, India
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: xBrowse color a cell ( again )
Posted: Tue Sep 14, 2010 03:47 PM
Rao

Your answer was perfect .. had a run-time error .. but I easily corrected it .. you just left out the third parameter "RED" for the decode .. you had the color attributes but left out the "RED" parameter ..

Thanks for your quick responce .. Send me a note from time to time .. I got locked out of my yahoo account and created a new e-mail .. r1.1955@live.com.

Thanks
Rick Lipkin

Code (fw): Select all Collapse
oBrw:oCol( "Last Status" ):bClrStd := ;
                 { || HB_Decode( AllTrim( oBrw:oCol("Last Status"):value ), ;
                      "GREEN", { CLR_WHITE, CLR_GREEN }, ;
                      "YELLOW", { CLR_BLACK, CLR_YELLOW }, ;
                      "RED",    { CLR_WHITE, CLR_RED } ) }

Continue the discussion