Page 2 of 2

Re: Grid Values

Posted: Thu Aug 11, 2022 5:08 pm
by franco
Thanks Gabor, This works but I need it refined.
What I want to do is if field-> value is 1 i want only column1 with color the other columns are black ( this works as a second header
Otherwise all columns are coloured as below but I cannot get if yo work in grid for dynamicbackcolor

Code: Select all

public bl
	public blcolor :=   {0,0,0}    
	public bcolor  :=   { || if (this.Cellrowindex/2 == int(this.CellRowIndex/2) ,{210,120,255}, {100,100,255})} 
if field->code == 1
bl := .t.
else 
bl := .f.
endif
 IN GRID
if bl = .t.		  
			dynamicbackcolor{ bcolor,blcolor,blcolor,blcolor,blcolor,blcolor}
else		 
			dynamicbackcolor{bcolor,bcolor,bcolor,bcolor,bcolor,bcolor}
endif

Re: Grid Values

Posted: Mon Aug 15, 2022 10:19 am
by mlnr
Hi Franco,

Maybe I don't understand what you want.
If the value of the field is 1 in the first column, should the entire column be colored and not just the given cell?

Or is that what you meant?

Re: Grid Values

Posted: Mon Aug 15, 2022 4:04 pm
by franco
Yes Gabor, what I want is this but, also the other rows tow different colors.
{ || if (this.Cellrowindex/2 == int(this.CellRowIndex/2) ,{210,120,255}, {100,100,255})} but if any grid field = 1 its pink.

Re: Grid Values

Posted: Mon Aug 15, 2022 4:49 pm
by Red2
Hi Franco,

I am not sure that I correctly understand you need.
If mlnr's suggestion is helpful then I wonder if your CodeBlock might use a different Function for each column.
My example, below, purposly calls the same function, GetColumnBackColor(), for each of the 4 columns.
Perhps you could adapt the following with, instead, column-specific functions:

Code: Select all

//// In Main.PRG
PUBLIC gnRowNbr    := 0		// See: function GetColumnBackColor()
PUBLIC gaRowColor  := {}	// See: function GetColumnBackColor()
// There are only 3 Columns in this example
PUBLIC gaBrowseStateDynamicBackColor :=	{ {|x, CellRowIndex | GetColumnBackColor( This.CellRowIndex ) }	;
										, {|x, CellRowIndex | GetColumnBackColor( This.CellRowIndex ) } ;
										, {|x, CellRowIndex | GetColumnBackColor( This.CellRowIndex ) } ;
										, {|x, CellRowIndex | GetColumnBackColor( This.CellRowIndex ) } }
//////////////////////////////
* - - - - - - - - - - - - -
FUNCTION GetColumnBackColor( param_CellRowIndex )
// Called from DynamicBackColor CodeBlock
LOCAL lcReturnVal := {}
	DO CASE

	CASE ( gnRowNbr == param_CellRowIndex )
		// Short circut - Row color already calculated!
		lcReturnVal := gaRowColor

	CASE ( gcStateMergeFldType == "C" )    /*  {"TEXTBOX"}  */
		/*  Magic number 1 (below) is the column number for By_State->MergeState:  */
		lcReturnVal := iif( ( ( GetProperty( "Main", "BrowseStates", "CellEx", param_CellRowIndex, gnColTest ) == "Y" ) ) ;
						,  iif( GetProperty( "Main", "BrowseStates", "CellEx", param_CellRowIndex, 1 ) != "Y" ;
							  , {255,255,255}, {190,255,170} ),  {255,150,150} )	

	CASE ( gcStateMergeFldType == "L" )    /*  {"CHECKBOX"}  */
		lcReturnVal := iif( ( ( GetProperty( "Main", "BrowseStates", "CellEx", param_CellRowIndex, gnColTest ) == "Y" ) ) ;
				  , iif( empty( GetProperty( "Main", "BrowseStates", "CellEx", param_CellRowIndex, 1 ) ) ;
					     ,  {255,255,255}, {190,255,170} ),  {255,150,150} )
	END CASE
	gnRowNbr++
	gaRowColor := lcReturnVal
RETURN lcReturnVal
// End function GetColumnBackColor
In my example above each of the 4 columns uses the same DynamicBackColor.
Your CodeBlock might call appropriate "Column color" functions for each of your columns' needs.

I hope that this might be helpful.

Kind Regards,
Red2

Re: Grid Values

Posted: Thu Aug 18, 2022 10:32 am
by mlnr
Hi Franco,

Please, try this

Code: Select all

bColor := { || if ( This.CellRowIndex/2 == int(This.CellRowIndex/2) , { 222,222,222 } , { 255,255,255 } ) }	
blColor := { || If(AtCellCol(1)=1, {210,120,255}, BLACK)}

Code: Select all

dynamicbackcolor{bcolor,blcolor,blcolor,blcolor,blcolor,blcolor};

Code: Select all

Function AtCellCol(nColIndex)

	Local nRowIndex := This.CellRowIndex
	Local nRet := GetProperty( "Form_1", "Grid_1", "CellEx", nRowIndex, nColIndex )
  
Return nRet

Re: Grid Values

Posted: Fri Aug 19, 2022 3:30 pm
by franco
Thanks for now I am gone for a week.
You both have given me ideas, I will try when I get back.
Franco

Re: Grid Values

Posted: Fri Sep 16, 2022 8:31 pm
by franco
I want to thank everyone for help.
This is what I ended up with and works great.
Each cell has a code EST for estimate or INV for invoice, or nothing for non recorded schedule.
The black separates the the days.
I built this using grid28 in samples.

Code: Select all

Function Main

Local aValue := { Nil , Nil }

PUBLIC b1Color :=  { || if ( This.CellRowIndex/2 == int(This.CellRowIndex/2) , { 222,222,222 } , { 255,255,255 } )}

 PUBLIC b2Color := { || If( AtCellCol(2)=="':';", BLACK , ;
                        If( AtCellCol(2)="INV",YELLOW, ;
			if( AtCellCol(2)="EST",GREEN, ;
			If( This.CellRowIndex/2 == int(This.CellRowIndex/2) , {222,222,222} , ;
				{ 255,255,255})))) } 
   

 PUBLIC b3Color := { || If( AtCellCol(3)=="':';", BLACK , ;
                        If( AtCellCol(3)="INV",YELLOW, ;
			if( AtCellCol(3)="EST",GREEN, ;
			If( This.CellRowIndex/2 == int(This.CellRowIndex/2) , {222,222,222} , ;
				{ 255,255,255})))) }
****** In my scheduler all fields are text so it works perfect.				
 ****** CAN NOT USE WITH LOGICAL, DATE ,MEMO at this time OK for me.
 
	DEFINE WINDOW Form_1 
	
	DEFINE GRID Grid_1 
			dynamicbackcolor{b1color,b2color,b3color,b1color,b1color,b1color}
		END GRID
	END WINDOW

Function AtCellCol(nColIndex)

	Local nRowIndex := This.CellRowIndex
	Local nRet := GetProperty( "Form_1", "Grid_1", "CellEx", nRowIndex, nColIndex )
  
Return nRet
HMG.jpg
HMG.jpg (141.14 KiB) Viewed 1700 times
e]

Thanks again for all ideas.
Franco