dynamicbackcolor in grid, how?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
dragancesu
Posts: 560
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia
Has thanked: 14 times
Been thanked: 101 times

dynamicbackcolor in grid, how?

Post by dragancesu » Thu Feb 08, 2018 8:02 am

the program reads mysql and writes to the grid

how to define a DYNAMICBACKCOLOR to coloring rows, like residents > 15,000,000

how referenced this field for examine

thank you

p.s. in config.ini is connection setting, just edit with notepad/notepad++ or same
Attachments
grid.zip
(16.89 KiB) Downloaded 46 times

User avatar
serge_girard
Posts: 2092
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 432 times
Been thanked: 92 times
Contact:

Post by serge_girard » Thu Feb 08, 2018 9:28 am

Hello Dragan,

I use this construction:

Code: Select all

Grid:
      DYNAMICBACKCOLOR  { { || BC_Grid_1()},{||BC_Grid_1()},{||BC_Grid_1()},{||BC_Grid_1()},{||BC_Grid_1()} }  // each column needs a call to  BC_Grid_1()



FUNCTION BC_Grid_1()
/**************************/
LOCAL a
LOCAL aColors  := {{ WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE,  ;
                     WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE,  ;
                     WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE,  ;
                     WHITE ,WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE } }  // EQUAL TO NUMBER OF COLUMNS == 32
LOCAL aItem    := Form_1.Grid_1.Item ( This.CellRowIndex ) 

IF aItem [30] == 'X' 
   FOR a = 1 TO 32
      aColors [1] [a] := MISTYROSE   
   NEXT a
ENDIF

 
IF aItem [31] == '=' 
   FOR a = 1 TO 32
      aColors [1] [a] := LAVENDER   
   NEXT a
ENDIF
 


IF val(aItem [32]) > 0 // GROUP
   FOR a = 1 TO 32
      aColors [1] [a] := HONEYDEW   
   NEXT a
ENDIF
 
RETURN aColors [1] [ This.CellColIndex ]
In BC_Grid_1() you can place any kind of condition in order to color any field.

Greetings, Serge

User avatar
serge_girard
Posts: 2092
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 432 times
Been thanked: 92 times
Contact:

Post by serge_girard » Thu Feb 08, 2018 10:42 am

Dragan,

I made a change in your mysqlfn.prg in order to get it working:

Code: Select all

If AScan( aDatabaseList, (_Database) ) == 0  // removed  Lower !!!!
  MsgINFO( "Database " + _Database + " doesn't exist!")
  Return Nil
EndIf 



User avatar
dragancesu
Posts: 560
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia
Has thanked: 14 times
Been thanked: 101 times

Post by dragancesu » Thu Feb 08, 2018 10:53 am

Thank you Serge

Post Reply