Page 1 of 1
Change columns color at run-time TXBrowse()? *Fixed Now*
Posted: Mon Apr 28, 2008 7:46 pm
by dutch
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.
Code: Select all
#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
Posted: Mon Apr 28, 2008 9:28 pm
by James Bott
Dutch,
Try this:
oBrw:aCols[n]:bClrStd := {|| iif(eval(oBrw:aCols[n]:bStrData)='X',{CLR_BLACK,CLR_RED},{CLR_BLACK,CLR_WHITE } }
James
Posted: Tue Apr 29, 2008 2:00 am
by dutch
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
oBrw:aCols[n]:bClrStd := {|| iif(aStatus[oBrw:nArrayAt][n]='X',{CLR_BLACK,CLR_RED},{CLR_BLACK,CLR_WHITE }) }
Posted: Tue Apr 29, 2008 4:21 am
by Richard Chidiak
Dutch
Xbrowse behaves a bit strange on evaluating colors, try it this way
oBrw:aCols:bClrStd := {|| {CLR_BLACK,iif(eval(oBrw:aCols[n]:bStrData)='X',CLR_RED,CLR_WHITE ) } }
HTH
Richard
Posted: Tue Apr 29, 2008 4:40 am
by James Bott
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 _ 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
Posted: Tue Apr 29, 2008 4:54 am
by dutch
Dear James,
In the past I use TWBrowse() to do as picture and now I would like to change to TXBrowse().
This is TWbrowse() code that I use. It is able to change bBkColor, bTextColor at runtime.
Code: Select all
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
Posted: Tue Apr 29, 2008 4:56 am
by dutch
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:bClrStd := {|| {CLR_BLACK,iif(eval(oBrw:aCols[n]:bStrData)='X',CLR_RED,CLR_WHITE ) } }
HTH
Richard
Regards,
Dutch
Posted: Tue Apr 29, 2008 5:08 am
by nageswaragunupudi
Please modify the code like this
Code: Select all
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.
Posted: Tue Apr 29, 2008 6:34 am
by dutch
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
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.
Code: Select all
#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
Posted: Tue Apr 29, 2008 7:10 am
by Richard Chidiak
Dutch
This is a piece of code from my application, it works OK
Code: Select all
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
Posted: Tue Apr 29, 2008 6:15 pm
by dutch
It work as spectation.
Thanks to all,
Dutch