DYNAMICBACKCOLOR Code Block

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Red2
Posts: 273
Joined: Sat May 18, 2019 2:11 pm
DBs Used: Visual FoxPro, FoxPro
Location: United States of America

DYNAMICBACKCOLOR Code Block

Post by Red2 »

Hi All,

(Google Spanish):
En un control BROWSE, el siguiente bloque de código muestra dinámicamente el color de fondo de mi fila.
Éxito en un BROWSE.
Sin embargo, cambiar el control a un control GRID quita el cambio de color de fondo de la fila.


In a BROWSE control the following code block dynamically displays my row's background color.
Success in a BROWSE.
However, changing the control to a GRID control removes the row's background color change. My code block:

Code: Select all

    bkRowColor := { || iif( ( ( By_State->LLR == "Y" ) ;
                         .OR. ( By_State->TAA == "Y" ) ;
                         .OR. ( By_State->OJG == "Y" ) ) ;
        , iif( empty( By_State->MergeState ), {255,255,255}, {190,255,170} ), {255,150,150} ) }
Something is different in a GRID control and I do not understand what.

A SIMPLE TEST EXAMPLE: C:\HMG.3.4.4\Samples\Controls\Grid\GRID_29\Demo.PRG
1) Make some changes to table TEST.DBF to vary the row's backcolor:
Some Test->Last values to empty and
Some Test->Married values to .F.
2) Make two additions to Demo.PRG
Add:

Code: Select all

    public bkRowColor := { || iif( ! empty( Test->Last ) ;
                         ,    iif( Test->Married == .T., {255,255,255}, {190,255,170} ), {255,150,150} ) }
// Add this as the last line in the GRID's declaration:
    DYNAMICBACKCOLOR  { bkRowColor, bkRowColor, bkRowColor, bkRowColor, bkRowColor, bkRowColor } 
I know am I missing or doing something wrong but what? Your guidance would be greatly appreciated.
Thank you,
Red2
franco
Posts: 821
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: DYNAMICBACKCOLOR Code Block

Post by franco »

In my grid columnwhen I have to separate each with brackets. May be your problem.
Maybe this.
public bkRowColor := { {|| iif( ! empty( Test->Last ) ;
, { || iif( Test->Married == .T. , 255,255,255, 190,255,170 ) } , 255,150,150 )} }

This works COLUMNWHEN { { || .F. },{ || iIf(HMG_GetLastVirtualKeyDown() == 13, .T., .F.)}, { || .T. },{ || .T. },{ || .F. }}
Does not work COLUMNWHEN { || .F. , iIf(HMG_GetLastVirtualKeyDown() == 13, .T., .F.), .T. , .T. , .F. }
All The Best,
Franco
Canada
Red2
Posts: 273
Joined: Sat May 18, 2019 2:11 pm
DBs Used: Visual FoxPro, FoxPro
Location: United States of America

Re: DYNAMICBACKCOLOR Code Block

Post by Red2 »

Thank you Franco for your suggestion.

My trying to add the additional "{ }" bracketing and "||" in your working
COLUMNWHEN to my DYNAMICBACKCOLOR code block has been confusing to me.

It is becoming quite complicated syntactically. My attempts to apply your pattern to:

Code: Select all

bkRowColor := { || iif( ! empty( Test->Last ) ;
                ,  iif( Test->Married == .T., {255,255,255}, {190,255,170} ), {255,150,150} ) }
have all yielded syntax errors.

Can you possibly show me the correct syntax with the above? I cannot seem to get it right.

Thanks again for your kind help.
Red2
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: DYNAMICBACKCOLOR Code Block

Post by serge_girard »

Red2,

I do it this way:

Code: Select all

....
@ 10,10 GRID Grid_BRS_SIS		;  
   WIDTH  1100			;
   HEIGHT 500			;    	 	 	 	 	 	 	 	
   HEADERS {'Id'    ,'x1', 'x2'  };
   WIDTHS  {50,      50 ,   150 } ;
   JUSTIFY {GRID_JTFY_LEFT, GRID_JTFY_LEFT, GRID_JTFY_LEFT     };
   FONT "Arial" SIZE 09	   ;
   ITEMS aBRS_SIS ;
   DYNAMICBACKCOLOR  { { || BC_Grid_BRS_SIS()}, {||BC_Grid_BRS_SIS()}, {||BC_Grid_BRS_SIS()}  }
....


STATIC FUNCTION BC_Grid_BRS_SIS
/*****************************/
LOCAL a
LOCAL aColors  := {{ HONEYDEW, HONEYDEW, HONEYDEW  } }  // EQUAL TO NUMBER OF COLUMNS == 3
LOCAL aItem    := Form_BROS_SIS.Grid_BRS_SIS.Item ( This.CellRowIndex )

 

DO CASE 
CASE ALLTRIM(aItem [3]) == 'P' 
   FOR a = 1 TO 3
      aColors [1] [a] := ORANGE
   NEXT a

OTHERWISE
   IF ALLTRIM(aItem [3]) == 'V' 
      FOR a = 1 TO 3
         aColors [1] [a] := MISTYROSE
      NEXT a
   ELSE
      FOR a = 1 TO 3
         aColors [1] [a] := LIGHTBLUE
      NEXT a

   ENDIF
ENDCASE

RETURN aColors [1] [ This.CellColIndex ]
Serge
There's nothing you can do that can't be done...
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: DYNAMICBACKCOLOR Code Block

Post by Claudio Ricardo »

Hi... I solve with this Forum help to:
In .FMG: // i need white background in first col

Code: Select all

DYNAMICBACKCOLOR { {255,255,255} , bColor , bColor , bColor , bColor , bColor , bColor , bColor , bColor, bColor , bColor , bColor , bColor , bColor , bColor , bColor , bColor, bColor , bColor , bColor , bColor , bColor , bColor , bColor , bColor, bColor }
In .prg:

Code: Select all

PRIVATE aColor := { 255,255,255 }	// Don't use LOCAL
PRIVATE bColor := {}

	bColor := { || If (This.CellColIndex == 2 , aColor := Propiedades_Grid_Pro_Color () , aColor ) }	

// Load Window... and etc...
Below:

Code: Select all

Function Propiedades_Grid_Pro_Color

LOCAL aColores := {}

	Do Case
	
		Case This.CellValue == "D"
	
			aColores := { 215,255,200 }

		Case This.CellValue == "A"

			aColores := { 215,215,215 }

		Case This.CellValue == "V"

			aColores := { 150,150,150 }

		Case This.CellValue == "P"

			aColores := { 255,180,180 }

		OtherWise
		
			aColores := { 255,255,255 }
			
	EndCase
	
Return aColores
Screenshot_20210803_092823.png
Screenshot_20210803_092823.png (13.31 KiB) Viewed 780 times
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
franco
Posts: 821
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: DYNAMICBACKCOLOR Code Block

Post by franco »

Sorry Red2, I think I read your post incorrect.
If your set color works Just do like Serge suggests.
DYNAMICBACKCOLOR { { || bkRowColor}, { || bkRowColor}, { || bkRowColor}, { || bkRowColor}, { || bkRowColor}, { || bkRowColor }}
I think I would handle this different.

Code: Select all

    public bkRowColor := {255,150,150}
    if ! empty() Test->Last  
          if Test->Married == .T.
                bkRowColor :=  {255,255,255}
          else
                bkRowColor := {190,255,170} 
          endif
    endif

// Add this as the last line in the GRID's declaration:
    DYNAMICBACKCOLOR  { { || bkRowColor}, { || bkRowColor}, { || bkRowColor}, { || bkRowColor}, { || bkRowColor}, { || bkRowColor }}
Franco
All The Best,
Franco
Canada
Red2
Posts: 273
Joined: Sat May 18, 2019 2:11 pm
DBs Used: Visual FoxPro, FoxPro
Location: United States of America

Re: DYNAMICBACKCOLOR Code Block

Post by Red2 »

(Google Spanish)
¡Muchas gracias a todos por sus amables sugerencias de control GRID! Noto que tanto el código de Serge como el de Claudio NO hacen referencia directa a los campos de la tabla, es decir, Test->Married.
En su lugar, los campos de la tabla se referencian indirectamente a través de la celda de row and column cell.

Pregunta fundamental:
¿La propiedad DYNAMICBACKCOLOR de GRID no funciona correctamente cuando se utilizan referencias de campo de tabla directas (Test->Married)?

Por lo tanto, ¿es esta fundamentalmente la razón por la que mi bloque de código original funciona perfectamente en un control BROWSE pero no puede funcionar en un control GRID?
================
Thank you all so much for your kind GRID control suggestions! I notice that both Serge's and Claudio's code does NOT directly reference the table fields, i.e. Test->Married.
Instead table fields there are indirectly referenced via the row and column cell.

Fundamental Question:
Does the GRID's DYNAMICBACKCOLOR property not work correctly when using direct table field references (such as Test->Married)?

Thus, is this fundamentally why my original code block works perfectly in a BROWSE control but cannot work in a GRID control?

Thanks again!
Red2
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: DYNAMICBACKCOLOR Code Block

Post by Claudio Ricardo »

Exacto... lo que me funcionaba bién en Browse no lo hacia en Grid, pero con la gran ayuda de este Foro lo solucioné.
Mi humilde opinion es que para DBF directa, es mejor Browse y para arrays o SQL Grid.

Exactly ... what worked well for me in Browse it did not work in Grid, but with the great help of this Forum I solved it.
IMHO is that, for direct DBF Browse is better, and for arrays or SQL Grid.
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
Red2
Posts: 273
Joined: Sat May 18, 2019 2:11 pm
DBs Used: Visual FoxPro, FoxPro
Location: United States of America

Re: DYNAMICBACKCOLOR Code Block

Post by Red2 »

Gracias Claudio, esta es una información crítica.
Estoy cambiando a un control GRID solo para poder realizar algunas mejoras en la pantalla.
¡Muchas gracias!
===================
Thank you Claudio, this is critical information.
I am changing to a GRID control only so I can make some display improvements.
Thanks so much!

Red2
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: DYNAMICBACKCOLOR Code Block

Post by srvet_claudio »

Los problemas que aparecen con frecuencia en el control grid con base de datos generalmente se deben a que se pasa por alto que el grid trabaja con registros logicos (grid row) y no con registros fisicos.

Ver el changelog:

The RECNO property of the Grid control not changes the current physical record number of the DBF file, only convert between the row of grid and the recno of the DBF.
- Get Grid.RECNO --> convert Logical record ( grid row ) to Physical record ( DBF recno )
- Set Grid.RECNO := XXX --> convert the Physical record XXX ( recno ) to Logical record ( grid row )
- Enhanced
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
Post Reply