Change columns color at run-time TXBrowse()? *Fixed Now*

Change columns color at run-time TXBrowse()? *Fixed Now*

Postby dutch » Mon Apr 28, 2008 7:46 pm

Dear All,

I try to set color CLR_RED for columns that content 'X' but it's not working.
How can I do that? This is image of my sample code.

Image
Code: Select all  Expand view  RUN
#include 'fivewin.ch'
#include 'xbrowse.ch'

FUNCTION Main

local oWnd, oBrw
local aStatus := { {'1','','X','','X'}, ;
         {'2','X','X','','X'}, ;
         {'3','','','X','X'} }
local n

   DEFINE WINDOW oWnd TITLE "Change columns colors"

   oBrw := TXBrowse():New( oWnd )

   oBrw:nMarqueeStyle       := MARQSTYLE_HIGHLCELL
   oBrw:nColDividerStyle    := LINESTYLE_BLACK
   oBrw:nRowDividerStyle    := LINESTYLE_BLACK
   oBrw:nFreeze             := 1
   oBrw:bLDblClick       := {|nRow,nCol,nKeyFlag| msginfo( eval(oBrw:acols[oBrw:nAt()]:bStrData) ) }

   oBrw:SetArray( aStatus )

   for n := 1 to len(aStatus)
       oBrw:aCols[n]:bClrStd := {|| { CLR_BLACK, iif(eval(oBrw:aCols[n]:bStrData)='X',CLR_RED,CLR_WHITE) } }
   next

   oBrw:CreateFromCode()

   oWnd:oClient := oBrw

   ACTIVATE WINDOW oWnd ON INIT oBrw:SetFocus()

return nil


Regards,
Dutch
Last edited by dutch on Tue Apr 29, 2008 6:06 pm, edited 1 time in total.
User avatar
dutch
 
Posts: 1543
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Postby James Bott » Mon Apr 28, 2008 9:28 pm

Dutch,

Try this:

oBrw:aCols[n]:bClrStd := {|| iif(eval(oBrw:aCols[n]:bStrData)='X',{CLR_BLACK,CLR_RED},{CLR_BLACK,CLR_WHITE } }

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby dutch » Tue Apr 29, 2008 2:00 am

Dear James,

It still doesn't work. It likes the eval(oBrw:aCols[n]:bStrData) don't return correctly.

James Bott wrote:Dutch,

Try this:
oBrw:aCols[n]:bClrStd := {|| iif(eval(oBrw:aCols[n]:bStrData)='X',{CLR_BLACK,CLR_RED},{CLR_BLACK,CLR_WHITE } }

James


I try this code but still doesn't work.
Code: Select all  Expand view  RUN
oBrw:aCols[n]:bClrStd := {|| iif(aStatus[oBrw:nArrayAt][n]='X',{CLR_BLACK,CLR_RED},{CLR_BLACK,CLR_WHITE }) }
User avatar
dutch
 
Posts: 1543
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Postby Richard Chidiak » Tue Apr 29, 2008 4:21 am

Dutch

Xbrowse behaves a bit strange on evaluating colors, try it this way

oBrw:aCols[I]:bClrStd := {|| {CLR_BLACK,iif(eval(oBrw:aCols[n]:bStrData)='X',CLR_RED,CLR_WHITE ) } }

HTH

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Postby James Bott » Tue Apr 29, 2008 4:40 am

Dutch,

>I try to set color CLR_RED for columns that content 'X' but it's not working

I think you have problem with this logic. Do you want to change the color of the entire colomn if there is a X in any row in the column? If so this is going to be very hard to do. You will need to scan the entire database looking for X's before you decide which color to make the column.

You can't do this with a codeblock that is only looking at the current row.

Perhaps I don't understand what you are trying to do?

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby dutch » Tue Apr 29, 2008 4:54 am

Dear James,

In the past I use TWBrowse() to do as picture and now I would like to change to TXBrowse().
Image

This is TWbrowse() code that I use. It is able to change bBkColor, bTextColor at runtime.

Code: Select all  Expand view  RUN
   
   REDEFINE LISTBOX oBrw FIELDS  "" ;
       ID 103 ;
                          OF oDlg

   oBrw:nAt       := 1
   oBrw:bLine     := { || aRmNo[oBrw:nAt] }
   oBrw:bGoTop     := { || oBrw:nAt := 1 }
   oBrw:bGoBottom := { || oBrw:nAt := Eval( oBrw:bLogicLen ) }
   oBrw:bSkip     := { | nWant, nOld | nOld := oBrw:nAt, oBrw:nAt += nWant,;
                   oBrw:nAt := Max( 1, Min( oBrw:nAt, Eval( oBrw:bLogicLen ) ) ),;
                   oBrw:nAt - nOld }

   oBrw:bLogicLen:= { || Len( aRmNo ) }
   oBrw:SetArray( aRmNo )

   oBrw:lDrawSelect  := .T.
   oBrw:aColSizes    := aSizes
   oBrw:aHeaders     := aHead
   oBrw:aJustify     := aJust
   oBrw:aHJustify    := aHJust
   oBrw:lAdjBrowse   := .F.
   oBrw:lAdjLastCol  := .F.
   oBrw:lCellStyle   := .T.
   oBrw:nLineStyle   := 11
   oBrw:nFreeze      := 1
   oBrw:nLineHeight  := 20
   oBrw:nHeaderHeight:= 22
   oBrw:lMChange     := .F.
   oBrw:bGoLeft      := {|| oBrw:nColAct > 2 }
   oBrw:bBkColor     := {|nRow,nCol,nStyle| if(nStyle=0,SetClr(oBrw:nAt,nCol,nStyle,oBrw,aRmSt),) }
   oBrw:bTextColor   := {|nRow,nCol,nStyle| if(nStyle=1,SetClr(oBrw:nAt,nCol,nStyle,oBrw,aRmSt),) }
*  oBrw:bFont        := {|nRow,nCol,nStyle| if(nStyle=1.and.aDate[nCol]=1, oFnt:hFont , if(nStyle=0.or.nStyle=3, oFont:hFont , ) ) }
   oBrw:bChange      := {|| oBrw:Refresh() }

   oBrw:nClrNFFore   := oBrw:nClrText
   oBrw:nClrNFBack   := oBrw:nClrPane


Regards,
Dutch
User avatar
dutch
 
Posts: 1543
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Postby dutch » Tue Apr 29, 2008 4:56 am

Dear Richard,

Your example is the same first sample above and It doesn't work correctly.

Richard Chidiak wrote:Dutch

Xbrowse behaves a bit strange on evaluating colors, try it this way

oBrw:aCols[I]:bClrStd := {|| {CLR_BLACK,iif(eval(oBrw:aCols[n]:bStrData)='X',CLR_RED,CLR_WHITE ) } }

HTH

Richard


Regards,
Dutch
User avatar
dutch
 
Posts: 1543
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Postby nageswaragunupudi » Tue Apr 29, 2008 5:08 am

Please modify the code like this
Code: Select all  Expand view  RUN
   for n := 1 to len(aStatus)
       oBrw:aCols[n]:bClrStd := { || CellColor( oBrw, n ) }
   next

...
...

//-----------------------------//
static function CellColor( oBrw, n )
return {|| { CLR_BLACK, iif(eval(oBrw:aCols[n]:bStrData)='X',CLR_RED,CLR_WHITE) } }
//-----------------------------//


The problem is because of using loop variable to construct a codeblock.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10651
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby dutch » Tue Apr 29, 2008 6:34 am

Dear nageswaragunupudi

I try as your suggestion and now it shows correctly as following code

nageswaragunupudi wrote:Please modify the code like this
Code: Select all  Expand view  RUN
   for n := 1 to len(aStatus)
       oBrw:aCols[n]:bClrStd := { || CellColor( oBrw, n ) }
   next

...
...

//-----------------------------//
static function CellColor( oBrw, n )
return {|| { CLR_BLACK, iif(eval(oBrw:aCols[n]:bStrData)='X',CLR_RED,CLR_WHITE) } }
//-----------------------------//


The problem is because of using loop variable to construct a codeblock.


Image

Code: Select all  Expand view  RUN
#include 'fivewin.ch'
#include 'xbrowse.ch'

FUNCTION Main

local oWnd, oBrw
local aStatus := { {'1','','X','','X'}, ;
         {'2','X','X','','X'}, ;
         {'3','','','X','X'} }
local n

   DEFINE WINDOW oWnd TITLE "Change columns colors"

   oBrw := TXBrowse():New( oWnd )

   oBrw:nMarqueeStyle       := MARQSTYLE_HIGHLCELL
   oBrw:nColDividerStyle    := LINESTYLE_BLACK
   oBrw:nRowDividerStyle    := LINESTYLE_BLACK
   oBrw:nFreeze             := 1
   oBrw:bLDblClick       := {|nRow,nCol,nKeyFlag| msginfo( eval(oBrw:acols[oBrw:nAt()]:bStrData) ) }

   oBrw:SetArray( aStatus )


   for n := 1 to len(aStatus[1])
       oBrw:aCols[n]:bClrStd := CellColor( oBrw, n )
   next
/*
   for n := 1 to len(aStatus)
       * oBrw:aCols[n]:bClrStd := {|| { CLR_BLACK, iif(eval(oBrw:aCols[n]:bStrData)='X',CLR_RED,CLR_WHITE) } }
       * oBrw:aCols[n]:bClrStd := {|| iif(eval(oBrw:aCols[n]:bStrData)='X',{CLR_BLACK,CLR_RED},{CLR_BLACK,CLR_WHITE }) }
       oBrw:aCols[n]:bClrStd := {|| iif(aStatus[oBrw:nArrayAt][n]='X',{CLR_BLACK,CLR_RED},{CLR_BLACK,CLR_WHITE }) }
   next
*/

   oBrw:CreateFromCode()

   oWnd:oClient := oBrw

   ACTIVATE WINDOW oWnd ON INIT oBrw:SetFocus()

return nil


static function CellColor( oBrw, n )
return {|| { CLR_HCYAN, iif(eval(oBrw:aCols[n]:bStrData)='X',CLR_RED,CLR_WHITE) } }


Regards,
Dutch
Last edited by dutch on Tue Apr 29, 2008 6:12 pm, edited 5 times in total.
User avatar
dutch
 
Posts: 1543
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Postby Richard Chidiak » Tue Apr 29, 2008 7:10 am

Dutch

This is a piece of code from my application, it works OK

Code: Select all  Expand view  RUN
FOR I = 1 TO LEN(oBrw:aCols)
   oBrw:aCols[I]:nWidth    := ASIZE[I]
   oBrw:aCols[I]:oDataFont := {||IIF(DET->SDETAIL,TABCOL[12],IIF(DET->ENR = "3" .OR. DET->ENR = "1"  ,TABOBJ[04], TABCOL[11] ) )  }
   oBrw:aCols[I]:bClrStd := {|| {CLR_BLUE, If( DET->SDETAIL,CLR_YELLOW,CLR_WHITE)  } }
NEXT


HTH

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Postby dutch » Tue Apr 29, 2008 6:15 pm

It work as spectation.

Thanks to all,
Dutch
User avatar
dutch
 
Posts: 1543
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 78 guests