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!

DynamicForecolor

Status
Not open for further replies.

BRADLEY21

Programmer
Sep 19, 2002
35
US
I have read every thread on this subject. This is quite frustrating. In my grid I have one column that has a dollar amount. I want it to be red if negative or black if >= o.

I tried &quot;IIF(amount<0, RGB(255,0,0),RGB(0,0,0) )&quot; in the dynamicforecolor property but it does not work.

Any help would be well appreciated.

Thanks!!!
 
ejd
Try in the init of the grid
Code:
thisform.grid1.SetAll(&quot;dynamicbackcolor&quot;, ;
			&quot;IIF(amount< 0,RGB(255,255,0), RGB(255,255,255))&quot;, &quot;Column&quot;)
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
you cna also put what mike said in the init of the form. form objects get Instantiated before the init event of the form. Attitude is Everything
 
But won't that make all of the columns red when I only want the one column with the negative number to be red. The other columns may have posive numbers.
 
ejd

But won't that make all of the columns red when I only want the one column with the negative number to be red.

No, the IIF (immediate IF) evaluates each record one at a time and if it's negative it will colorthe background color yellow (if you want red it's 255,0,0) otherwise it will be white (255,255,255)
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Yes you are right in reference to rows, but it does not evaluate each field. In my response I referred to all of the columns of a given row not vice versa.

The whole row will change, a relsult I do not want, the variable amount is a field.

I noticed that the property is accessible at this level but for some reason when I enter &quot;IIF(amount<0, RGB(255,0,0),RGB(0,0,0) )&quot; in the property it does not evaluate it.
 
ejd

Works for me. Here an example:
Run this in a prg

Code:
PUBLIC oForm
oForm1 = CREATEOBJECT(&quot;form1&quot;)
oForm1.addobject(&quot;grid1&quot;,&quot;grid1&quot;)
oForm1.show(1)


DEFINE CLASS GRID1 AS GRID
ColumnCount = 1
VISIBLE = .T.
COLUMN1.WIDTH = 200
PROCEDURE INIT
thisform.grid1.SetAll(&quot;dynamicbackcolor&quot;, ;
            &quot;IIF(amount< 0,RGB(255,0,0), RGB(255,255,255))&quot;, &quot;Column&quot;)
ENDPROC
ENDDEFINE


DEFINE CLASS form1 as form
PROCEDURE LOAD
CREATE cursor myCursor (amount n(10,2))
INSERT into myCursor (amount) values (100.00)
INSERT into myCursor (amount) values (200.00)
INSERT into myCursor (amount) values (-100.00)
INSERT into myCursor (amount) values (-100.00)
INSERT into myCursor (amount) values (500.00)
INSERT into myCursor (amount) values (1100.00)
INSERT into myCursor (amount) values (-2100.00)
GO top
ENDPROC
Mike Gagnon

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

Your example works fine, but the entire row turns red, I only want the cell with the negative number to turn red.




 
ejd
Your example works fine, but the entire row turns red, I only want the cell with the negative number to turn red.

Sorry, I misread your question.

Change this line:
Code:
thisform.grid1.SetAll(&quot;dynamicbackcolor&quot;, ;
            &quot;IIF(amount< 0,RGB(255,0,0), RGB(255,255,255))&quot;, &quot;Column&quot;)

to
thisform.grid1.SetAll(&quot;dynamicforecolor&quot;, ;
&quot;IIF(amount< 0,RGB(255,0,0), RGB(0,0,0))&quot;, &quot;Column&quot;)




Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Hi EJD,

In the initevent of the form.. add the code..

ThisForm.Grid1.ColumnN.DynamicForeColor = ;
&quot;IIF(amount< 0,RGB(255,0,0),RGB(0,0,0))&quot;

Where ColumnN is the Coulmn1 or 2 or 3 whatever.

This will get you the result. :) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top