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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Color coding a vfp6 grid

Status
Not open for further replies.

cobbycoker

Programmer
Nov 20, 2002
7
GH
Hi all,

I'm rewriting a Paradox app in vfp6. I have a form with a grid which has a date column. The request is for dates in the column earlier than today to appear in red and larger font, while the other dates appear in normal black.

This is fairly easy to do in Paradox, but I can't seem to find out how vfp does it, either interactively or in code.

Any help to this vfp newbie from you gurus out there will be appreciated.

Thanks,

Cobby

 
cobbycoker

Here is FAQ184-1939 transformed to show a red textbox for any dates in the data below "01/04/2002". Of course this does not have to be done programmatically.

Code:
oForm=CREATEOBJECT("myForm")
oForm.ADDOBJECT('myGrid1','myGrid')
oForm.myGrid1.column1.header1.CAPTION = "Name"
oForm.myGrid1.column2.header1.CAPTION = "Date"
oForm.myGrid1.column2.sparse = .f.
oForm.myGrid1.column2.ADDOBJECT("TextRed1","TextRed")
oForm.SHOW(1)
DEFINE CLASS myForm AS FORM
    AUTOCENTER = .T.
    PROCEDURE LOAD()
    CREATE CURSOR myCursor (NAME C(20),date d)
    INSERT INTO myCursor (NAME,date) VALUES ("MIKE",CTOD("01/01/2002"))
    INSERT INTO myCursor (NAME,date) VALUES ("JOHN",CTOD("01/02/2002"))
    INSERT INTO myCursor (NAME,date) VALUES ("PAUL",CTOD("01/03/2002"))
    INSERT INTO myCursor (NAME,date) VALUES ("FRANK",CTOD("01/04/2002"))
    INSERT INTO myCursor (NAME,date) VALUES ("JOHN",CTOD("01/05/2002"))
    GO TOP
ENDPROC
ENDDEFINE

DEFINE CLASS myGrid AS GRID
    VISIBLE = .T.
    COLUMNCOUNT = 2
    WIDTH = 200
    TOP = 20
    LEFT = 20
    PROCEDURE INIT()
    WITH THIS
        .column2.DYNAMICCURRENTCONTROL = "dynamic()"
    ENDWITH
ENDPROC
ENDDEFINE
DEFINE CLASS TextRed AS TEXTBOX
    BACKCOLOR = RGB(255,0,0)
    VISIBLE = .T.
ENDDEFINE

FUNCTION DYNAMIC
IF myCursor.date < CTOD(&quot;01/04/2002&quot;)
    RETURN &quot;textRed1&quot;
ELSE
    RETURN &quot;TEXT1&quot;
ENDIF   
ENDFUNC
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first or check this link
 
HI
In the init of the grid.. put the code..
** Replace the column number to suit your need.

this.Columns(3).DynamicFontBold = &quot;myFieldDate > varDate&quot;
this.Columns(3).DynamicFontUnderline = &quot;myCondition&quot;
this.Columns(3).DynamicForeColor = ;
&quot;IIF(myDate > varDate,RGB(255,0,0),RGB(0,0,255))&quot;
this.Columns(3).DynamicBackColor = ;
&quot;IIF(myDate > varDate,RGB(0,0,255),RGB(255,0,0))&quot;

:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Ramani,
Based on your message above, I tried the following:

DODEFAULT()
FOR BOLDFONT = 1 TO This.ColumnCount
lcColumnVal = 'Column'+ALLTRIM(STR(BOLDFONT))
lcIIFVal = 'This.'+lcColumnVal+'.Text1.Value'
lcFontBold = 'This.'+lcColumnVal+'.DynamicFontBold'
IIF(ALLTRIM(&lcIIFVal) = '-Nothing-', &lcFontBold = &quot;.F.&quot;, &lcFontBold = &quot;.T.&quot;)
ENDFOR

in my Grid's init. The idea here is to be dynamic, and not have to specifiy every grid column. Where I have data, I want it to be BOLD. But, my IIF does not yeild bold values. The other thing I found curious is that DynamicFontBold's express has to be quoted. Is this where I've lost the plot? I've never seen logical values passed to a property in quotes, but if I take the quotes off, I get an Opperator/Operand type mismatch error. I just find this odd. What do I need to do to get this to work?

Best Regards,
Scott

&quot;Everything should be made as simple as possible, and no simpler.&quot;[hammer]
 
It's just the syntax of the Dynamicxxxxx() function. It expects a character expression for a given parameter so it knows what dynamic property it is setting. It just takes a little getting used to.
Dave S.
 
Dave,
I can live with that, but it's still not working on my form. :)
Any idea how I can fix up my code above so that it does? I'm not at all clear as to why it's not working. The IIF expression evaluates to &quot;-Nothing-&quot; on fields that have &quot;-Nothing-&quot; stored in them. So, why are the other fields not appearing in bold text? Best Regards,
Scott

&quot;Everything should be made as simple as possible, and no simpler.&quot;[hammer]
 
I use the actual data instead of the text, since the textX.value may not have been set yet. Try this in the Grid.Init:

WITH This
FOR i = 1 TO .COLUMNCOUNT
STORE 'column' + ALLTRIM(STR(i)) TO cColumn
.&cColumn..DYNAMICFONTBOLD = ;
&quot;IIF(MyTable.Field = '-Nothing-', .F., .T.)&quot;
NEXT
ENDWITH
Dave S.
 
Dave,
Well, that didn't specifically work, but you led me down another track, which is I believe doing what I'm asking for, but not what I want. Here's how the code looks now:

DODEFAULT()
*
FOR BOLDFONT = 1 TO This.ColumnCount
lcColumnVal = 'Column'+ALLTRIM(STR(BOLDFONT))
lcIIFVal = &quot;ALLTRIM(This.&quot;+lcColumnVal+&quot;.Text1.Value) = '-Nothing-'&quot;
This.&lcColumnVal..DynamicFontBold = IIF(&lcIIFVal,&quot;.F.&quot;,&quot;.T.&quot;)
ENDFOR

Much simpler than before.
The problem is, this affects the WHOLE colum. I only want it to effect the single cell within the column. Reason being, I may have 4 or 5 items in the grid. If the first item has a value other than -Nothing-, than it sets the whole column to bold, even if the next 4 items say -Nothing-. How can I get the individual cells to be bold if they have a value other than -Nothing-?
Best Regards,
Scott

&quot;Everything should be made as simple as possible, and no simpler.&quot;[hammer]
 
Hi Scott,

The way to go..

1. In the init event of the grid.. Add the code..
2. If column 5 is yout memoField column..

this.Columns(5).DynamicBackColor = ;
&quot;IIF(!EMPTY(MemoField),RGB(0,0,255),RGB(255,0,0))&quot;
or
this.Columns(5).DynamicFontBold = &quot;!EMPTY(MemoField)&quot;

Now for you to do a macro or such thing...
FOR EACH oColumn IN This.Columns
IF oColumn.ControlSource = &quot;MyFieldName&quot;
oColumn.DynamicFontBold = .....
ENDIF
ENDFOR

whatever.. way.. :) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
If you're only wanting to change one cell, maybe you should look at AfterRowColChange instead.
Dave S.
 
Dave,
Well, that's only relevant if I want the current row to be effected. I want all cells in the grid that do not contain -Nothing- to appear in a bold font. Am I over-complicating this thing?
Best Regards,
Scott

&quot;Everything should be made as simple as possible, and no simpler.&quot;[hammer]
 
Well now you've got me confused.

From one post:
The problem is, this affects the WHOLE colum. I only want it to effect the single cell within the column.

Then later:
I want all cells in the grid that do not contain -Nothing- to appear in a bold font.

Am I just not grasping what you are saying?
Dave S.
 
Dave,
Sorry for the confustion. What I have is a grid with 8 columns, some of which will say &quot;-Nothing-&quot;, and others which will have some other value. What I want is, if a cell in the grid has a value other than &quot;-Nothing-&quot;, than I want that cell to appear with a bold font. So, while I do want it to effect the &quot;Whole Column&quot;, I don't want it to be based on the first value. The problem with the solution above is, if the first value in the column determines if the whole column is displayed in bold or regular font type. I need the value of the cell's FontBold to reflect the contents of the cell, at all times.

Clear a mud????
Best Regards,
Scott

&quot;Everything should be made as simple as possible, and no simpler.&quot;[hammer]
 
Ok. I think I've got the idea. Sorry for the thick-skulledness. Try this:

AFIELDS(aFld)
WITH This
FOR i = 1 TO .COLUMNCOUNT
STORE 'column' + ALLTRIM(STR(i)) TO cColumn
.&cColumn..DYNAMICFONTBOLD = ;
&quot;IIF('-Nothing-' $ &afld[i,1], .F., .T.)&quot;
NEXT
ENDWITH
Dave S.
 
Dave,
Well, this doesn't work for 2 reasons:

1) AFIELDS assumes that the fields in my table match the fields in my grid. I've only got 8 fields in my grid, but there are about 15 fields in that table. So, it doesn't match the right column.

2) It still applies the DynamicFontBold to the COLUMN, not to the individual cell in the column, so once it gets set BOLD, than they all appear BOLD in that column.

What I'm after is:

FIELD1 FIELD2 FIELD3
-Nothing- Stuff -Nothing-
Stuff More Stuff -Nothing-
-Nothing -Nothing- Stuff

What I get with your example is:
FIELD1 FIELD2 FIELD3
-Nothing- Stuff -Nothing-
Stuff More Stuff -Nothing-
-Nothing -Nothing- Stuff

See the idea??

Also, in your code, its just slightly off, you would actually want:

Code:
 .&cColumn..DYNAMICFONTBOLD = ;
         IIF('-Nothing-' $ &afld[i,1], &quot;.F.&quot;, &quot;.T.&quot;)
(Just a minor issue with the quotes...)
Best Regards,
Scott

&quot;Everything should be made as simple as possible, and no simpler.&quot;[hammer]
 
The problem with relating the Dynamicxxxxx with Text1, as in:
This.column1.dynamicfontbold = ;
&quot;IIF(This.Column1.Text1.Value = '-Nothing-', .T., .F.)&quot;

is that the whole column will change as the current row changes. I tried it this way and it worked a lot better:

This.column1.dynamicfontbold = ;
&quot;IIF( MyTable.Field1 = '-Nothing-', .F., .T.)&quot;
This.column2.dynamicfontbold = ;
&quot;IIF( MyTable.Field2 = '-Nothing-', .F., .T.)&quot;
This.column3.dynamicfontbold = ;
&quot;IIF( MyTable.Field3 = '-Nothing-', .F., .T.)&quot;

More cut and paste, but I was getting a headache.
Dave S.
 
Thanks guys, for all the help and the education. I should have discovered this forum ages ago!

Cobby
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top