Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grid's dynamic color 2

Status
Not open for further replies.

sqlpro

Programmer
Dec 30, 2003
297
NZ
Hi friends

I have a grid which shows data abt user Tasks.
It displays completed and uncompleted Tasks.to show difference between them i change dynamic color of completed tasks like following...

Thisform.grid.SetAll("dynamicbackcolor","IIF(completed='Yes', RGB(192,255,192), RGB(255,255,255))", "Column")

so it is very easy to differentiate between completed and uncompleted tasks.
But i have new requirement came up i.e Merging Tasks
it means if they r 3 tasks (say 1,2,3) and 1,2 can b merged
into 3 .so there will b only one Task (i.e 3)
but the thing is when user selects a record for Merging i need to change its background color so its easy for user which tasks are tagged for Merging.
what i am doing is when user tags a record(pressing specebar) i am updating cursor with a value(grid bound to a cursor) and issuing following code

Thisform.grid.SetAll("dynamicbackcolor","IIF(cursearchtask.tagrecord =1, RGB(224,224,0),RGB(255,255,255))", "Column")

the problem with this is my previous setting for completed tasks are gone.
How can i keep my existing dynamic color and still b able
to add new color based on different criteria.
I appreciate ur Ideas
Thank you very much :)
 
Use nested immediate IF (IIF), here is example I use (just adjust it to suit your needs,BTW its a little tricky to configure). Just put it in the Init of the grid and anytime the values change just recall the init.
Code:
This.SetAll('DynamicBackColor', ;
"IIF(LEFT(ViewCustPlan1.SunStatus,1)='A',RGB(128,255,0),"+;
"IIF(LEFT(ViewCustPlan1.SunStatus,1)$ 'R',RGB(255,181,106),"+;
"IIF(LEFT(ViewCustPlan1.SunStatus,1)='P',IIF(ISDIGIT(SUBSTR(ViewCustPlan1.CODE,1,1)),RGB(138,255,255),RGB(255,255,128)),"+;
"RGB(255,128,128))))",'Column')

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Dear Mike Gagnon

Thank you for solution
sorry but i'm little confused how 2 use this

This.SetAll('DynamicBackColor', ;
"IIF(LEFT(ViewCustPlan1.SunStatus,1)='A',RGB(128,255,0),"+;
"IIF(LEFT(ViewCustPlan1.SunStatus,1)$ 'R',RGB(255,181,106),"+;
"IIF(LEFT(ViewCustPlan1.SunStatus,1)='P',IIF(ISDIGIT(SUBSTR(ViewCustPlan1.CODE,1,1)),RGB(138,255,255),RGB(255,255,128)),"+;
"RGB(255,128,128))))",'Column')

can i replace ViewCustPlan1.sunstatus with "completed" and
ViewCustPlan1.code with "tagrecord"?
following 2 line are my actual stmts

1)Thisform.grid.SetAll("dynamicbackcolor","IIF(completed='Yes', RGB(192,255,192), RGB(255,255,255))", "Column")

2)Thisform.grid.SetAll("dynamicbackcolor","IIF(cursearchtask.tagrecord =1, RGB(224,224,0),RGB(255,255,255))", "Column")

Thank you very much
 
Dear Mike Gagnon
I changed my command like following it is not doing anything
i mean grid's background color always staying white

.SetAll("dynamicbackcolor","IIF(completed='Yes', RGB(192,255,192),"+;
"IIF(cursearchtask.tagrecord =1, RGB(224,224,0),RGB(255,255,255)),"+;
"RGB(255,255,255))",'Column')
 
It looks like you've got an extra setting at the end of your code.

When the command in a Dynamic anything field gets complex like this, I prefer to call a UDF instead. It's much more readable.

In your DynamicBackColor property, put SetGridBackColor()

Assuming you have a PRG-based procedure file that is not part of a class, you would create SetGridBackColor as follows:
Code:
Function SetGridBackColor
   local lcReturn

   Do Case
   case completed='Yes'
      lcReturn = "RGB(192,255,192)"
   case cursearchtask.tagrecord = 1
      lcReturn = "RGB(224,224,0)"
   otherwise
      lcReturn = "RGB(255,255,255)"
   Endcase
Endfunc


-BP (Barbara Peisch)
 
Hi Barbara Peisch
Thanks for the idea.
I tried it .it worked in a different way.
it displays color only when we pointer is on tagged record
if we move cursor pointer to next record then all grid rows
are shown in white color.
Actually the grid created from class which we created from
default foxpro grid and added many new properties and methods.
i am just confused where to look for and what to look for.
 
Hi Barbara Peisch
IT WORKED :)
I CREATED A FORM LEVEL METHOD
LIKE FOLLOWING

local lcReturn

lcReturn=''
Do Case
case UPPER(ALLTRIM(cursearchtask.completed))='YES'
lcReturn = RGB(192,255,192)
case cursearchtask.tagrecord = 1
lcReturn = RGB(224,224,0)
otherwise
lcReturn = RGB(255,255,255)
Endcase
RETURN lcReturn

AND FORGOT ADD LAST LINE I.E RETURN lcReturn
tHANK YOU VERY MUCH
CHEERS
rAJANI
 
Here's an example of what Barbara is referring to:

[tt]
LOCAL o
o = CREATEOBJECT("myform")
o.SHOW(1)

DEFINE CLASS myform AS FORM
DOCREATE = .T.
DATASESSION = 2
AUTOCENTER = .T.
CAPTION = "Multiple dynamic grid background colors"
WIDTH = 600
HEIGHT = 400
MINHEIGHT = 300
MINWIDTH = 300

ADD OBJECT grid1 AS GRID WITH ;
HEIGHT = THIS.HEIGHT, ;
WIDTH = THIS.WIDTH, ;
DELETEMARK = .F.

PROCEDURE LOAD
SELECT * FROM (_samples+"\data\customer") ORDER BY MaxOrdAmt DESC INTO CURSOR TmpCust

* Should have error test here

USE IN "customer"
ENDPROC

PROCEDURE INIT
* You can pass in resonable number of params in
* the call to GetBackColor() i.e. Completed, tagrecord, etc.
THISFORM.grid1.SETALL("dynamicbackcolor","thisform.GetBackColor(allt(country))")
ENDPROC

PROCEDURE RESIZE
THIS.grid1.WIDTH = THIS.WIDTH
THIS.grid1.HEIGHT = THIS.HEIGHT
ENDPROC

FUNCTION GetBackColor(cCountry)
LOCAL nColor
DO CASE
CASE cCountry == "Germany"
nColor = RGB(255,255,255)
CASE cCountry == "UK"
nColor = RGB(224,224,0)
CASE cCountry == "Sweden"
nColor = RGB(224,224,160)
CASE cCountry == "France"
nColor = RGB(100,224,160)
CASE cCountry == "Spain"
nColor = RGB(100,224,160)
OTHERWISE
nColor = RGB(224,100,224)
ENDCASE
RETURN nColor
ENDFUNC
ENDDEFINE

[/tt]
 
cheers my friend :)
i understood now
cheers
Rajani
 
AND FORGOT ADD LAST LINE I.E RETURN lcReturn

Sorry, that was my fault. I forgot to include the RETURN in my code example. At least you got it figured out.



-BP (Barbara Peisch)
 
Thank you very much for your valuable time Barbara Peisch
cheers
Rajani
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top