Dynamic Colors in GRID

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

Post Reply
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Dynamic Colors in GRID

Post by esgici »

Hi to all

I can't succeed dynamically set/changing back and fore colors of GRID cells.

Here my unsucceed :( code :

Code: Select all


#include "minigui.ch"

PROC Main()

    PRIV aGrdDFC   := ARRAY( 3 )      // GRID Dynamic Fore Colors   
         aCitizens := {}
         
    DEFINE WINDOW Form_1 ;
        AT 0,0 ;
        WIDTH 500 ;
        HEIGHT 400 ;
        TITLE 'Test Dynamic Colors' ;
        MAIN ;
        ON INIT FillGrid()
        
        DEFINE GRID Grid_1
            ROW     10
            COL     10
            WIDTH   450
            HEIGHT  330
            HEADERS {'Last Name','First Name','Phone'}
            WIDTHS  {140,140,140}
            ITEMS   { { '','',''} }
            VALUE   1
        END GRID

    END WINDOW

    Form_1.Center

    Form_1.Activate

RETU // Main()

*------------------------------------------------------------------------

PROC FillGrid()

  LOCA aItems :={ {'Simpson','Homer','555-5555' },;
                  {'Mulder','Fox','324-6432'},;
                  {'Smart','Max','432-5892'},;
                  {'Grillo','Pepe','894-2332'},;
                  {'Kirk','James','346-9873'},;
                  {'Barriga','Carlos','394-9654'},;
                  {'Flanders','Ned','435-3211'},;
                  {'Smith','John','123-1234'},;
                  {'Pedemonti','Flavio','000-0000'},;
                  {'Gomez','Juan','583-4832'},;
                  {'Fernandez','Raul','321-4332'},;
                  {'Borges','Javier','326-9430'},;
                  {'Alvarez','Alberto','543-7898'},;
                  {'Gonzalez','Ambo','437-8473'},;
                  {'Batistuta','Gol','485-2843'},;
                  {'Vinazzi','Amigo','394-5983'},;
                  {'Pedemonti','Flavio','534-7984'},;
                  {'Samarbide','Armando','854-7873'},;
                  {'Pradon','Alejandra','???-????'},;
                  {'Reyes','Monica','432-5836'} }
                  
   Form_1.Grid_1.DeleteAllItems()
   
   AEVAL( aItems, { | a1 | Form_1.Grid_1.AddItem( a1 ) } )

   AEVAL( aItems, { | a1 | AADD( aCitizens, LEFT( a1[ 3 ], 1 ) == "5" ) } )
   
   AFILL( aGrdDFC, { || IF( aCitizens[ This.CellRowIndex ], RED, GREEN ) } )     

   *** Form_1.Grid_1.DynamicForeColor := aGrdDFC  => syntax error at '.'
   
   SetProperty ( 'Form_1', 'Grid_1', 'DYNAMICFORECOLOR', aGrdDFC )      

RETU // FillGrid()
Any opinion :?:

Regards

--

esgici
Viva INTERNATIONAL HMG :D
User avatar
gfilatov
Posts: 1057
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Dynamic Colors in GRID

Post by gfilatov »

esgici wrote:Hi to all

I can't succeed dynamically set/changing back and fore colors of GRID cells.

...

Any opinion :?:
Hi Esgici,

Try the following working sample:

Code: Select all

#include "minigui.ch"

PROC Main()

    PRIV bColor1 := {|| NIL }
    PRIV bColor2 := { || if ( LEFT( This.CellValue, 1 ) == "5" , RED, GREEN ) }
         
    DEFINE WINDOW Form_1 ;
        AT 0,0 ;
        WIDTH 500 ;
        HEIGHT 400 ;
        TITLE 'Test Dynamic Colors' ;
        MAIN ;
        ON INIT FillGrid()
        
        DEFINE GRID Grid_1
            ROW     10
            COL     10
            WIDTH   450
            HEIGHT  330
            HEADERS {'Last Name','First Name','Phone'}
            WIDTHS  {140,140,140}
            ITEMS   { { '','',''} }
            VALUE   1
            DYNAMICFORECOLOR { bColor1, bColor1, bColor2 } 
        END GRID

    END WINDOW

    Form_1.Center

    Form_1.Activate

RETU // Main()

*------------------------------------------------------------------------

PROC FillGrid()

  LOCA aItems :={ {'Simpson','Homer','555-5555' },;
                  {'Mulder','Fox','324-6432'},;
                  {'Smart','Max','432-5892'},;
                  {'Grillo','Pepe','894-2332'},;
                  {'Kirk','James','346-9873'},;
                  {'Barriga','Carlos','394-9654'},;
                  {'Flanders','Ned','435-3211'},;
                  {'Smith','John','123-1234'},;
                  {'Pedemonti','Flavio','000-0000'},;
                  {'Gomez','Juan','583-4832'},;
                  {'Fernandez','Raul','321-4332'},;
                  {'Borges','Javier','326-9430'},;
                  {'Alvarez','Alberto','543-7898'},;
                  {'Gonzalez','Ambo','437-8473'},;
                  {'Batistuta','Gol','485-2843'},;
                  {'Vinazzi','Amigo','394-5983'},;
                  {'Pedemonti','Flavio','534-7984'},;
                  {'Samarbide','Armando','854-7873'},;
                  {'Pradon','Alejandra','???-????'},;
                  {'Reyes','Monica','432-5836'} }
                  
   Form_1.Grid_1.DeleteAllItems()
   
   AEVAL( aItems, { | a1 | Form_1.Grid_1.AddItem( a1 ) } )

RETU // FillGrid()
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Dynamic Colors in GRID

Post by esgici »

gfilatov wrote:
Try the following working sample
Thanks gfilatov.

This method is already used.

You are assigned value at design time.

This means that "DYNAMICxxxCOLOR property of GRID doesn't accept value at run time "?

Regards

--

esgici
Viva INTERNATIONAL HMG :D
User avatar
gfilatov
Posts: 1057
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Dynamic Colors in GRID

Post by gfilatov »

esgici wrote:
gfilatov wrote: ...
This means that "DYNAMICxxxCOLOR property of GRID doesn't accept value at run time "?
esgici,

Sure. And reference should be updated as following
-------------------------------------------------------------------------------
@...GRID / DEFINE GRID: Creates a grid control.
-------------------------------------------------------------------------------
...
- Properties:
...
- DynamicBackColor (D)
- DynamicForeColor (D)
...

D: Available at control definition only
But the following sample have a trick:

Code: Select all

#include "minigui.ch"

PROC Main()

    PRIV bColor1 := {|| NIL}
    PRIV bColor2 := { || if ( LEFT( This.CellValue, 1 ) == "5" , RED, GREEN ) }
         
    DEFINE WINDOW Form_1 ;
        AT 0,0 ;
        WIDTH 500 ;
        HEIGHT 400 ;
        TITLE 'Test Dynamic Colors' ;
        MAIN ;
        ON INIT FillGrid()
        
        DEFINE GRID Grid_1
            ROW     10
            COL     10
            WIDTH   450
            HEIGHT  330
            HEADERS {'Last Name','First Name','Phone'}
            WIDTHS  {140,140,140}
            ITEMS   { { '','',''} }
            VALUE   1
            DYNAMICFORECOLOR { bColor1, bColor1, bColor1 }
        END GRID

    END WINDOW

    Form_1.Center

    Form_1.Activate

RETU // Main()

*------------------------------------------------------------------------

PROC FillGrid()

  LOCA k := GetControlIndex( 'Grid_1', 'Form_1' )
  LOCA aItems :={ {'Simpson','Homer','555-5555' },;
                  {'Mulder','Fox','324-6432'},;
                  {'Smart','Max','432-5892'},;
                  {'Grillo','Pepe','894-2332'},;
                  {'Kirk','James','346-9873'},;
                  {'Barriga','Carlos','394-9654'},;
                  {'Flanders','Ned','435-3211'},;
                  {'Smith','John','123-1234'},;
                  {'Pedemonti','Flavio','000-0000'},;
                  {'Gomez','Juan','583-4832'},;
                  {'Fernandez','Raul','321-4332'},;
                  {'Borges','Javier','326-9430'},;
                  {'Alvarez','Alberto','543-7898'},;
                  {'Gonzalez','Ambo','437-8473'},;
                  {'Batistuta','Gol','485-2843'},;
                  {'Vinazzi','Amigo','394-5983'},;
                  {'Pedemonti','Flavio','534-7984'},;
                  {'Samarbide','Armando','854-7873'},;
                  {'Pradon','Alejandra','???-????'},;
                  {'Reyes','Monica','432-5836'} }
                  
   Form_1.Grid_1.DeleteAllItems()
   
   AEVAL( aItems, { | a1 | Form_1.Grid_1.AddItem( a1 ) } )

   _HMG_SYSDATA [ 40 ] [ k ] [ 4 ] := { bColor1, bColor1, bColor2 }

   _HMG_DOGRIDREFRESH ( k )

RETU // FillGrid()
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Dynamic Colors in GRID

Post by Roberto Lopez »

...
This means that "DYNAMICxxxCOLOR property of GRID doesn't accept value at run time "?

esgici,

Sure. And reference should be updated as following
Anyway, DynamicBackColor and DynamicForecolor data is stored in control arrays and could be easy, access to it to modify at runtime.

Besides, it could be a good idea to add support to it in SetPtoperty and GetProperty functions.

Regards,

Roberto.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
Post Reply