Search code examples
visual-foxprofoxpro

Changing Grid row color based on values in that row


I have a grid with this columns : nrcrt, deadline, dateEnd, content. The deadline and dateEnd column format are "yyyy-MM-dd HH:mm:ss" I want to set Grid row color to red if deadline is greater than dateEnd and less than today.

thisform.grid1.SetAll("DynamicForeColor", "IIF(CTOD(SUBSTR(deadline , 1, 10)) >CTOD(SUBSTR(dateEnd , 1, 10)) and CTOD(SUBSTR(deadline , 1, 10)) <DATE() , 0, 255)")

but it doesn't work.


Solution

  • Note: Your expressions didn't really make sense to me, you should revise what you need:

    Create Cursor SampleData (Id i Autoinc, deadline c(20), dateEnd c(20))
    Insert Into SampleData (deadline, dateEnd) Values ('2016/02/29 11:30:00','')
    
    Insert Into SampleData (deadline, dateEnd) Values ('2016/02/01 12:00:00','2016/01/30 12:00:00')
    Insert Into SampleData (deadline, dateEnd) Values ('2016/02/01 12:00:00','2016/02/01 12:00:00')
    Insert Into SampleData (deadline, dateEnd) Values ('2016/02/01 12:00:00','2016/02/02 12:00:00')
    
    Insert Into SampleData (deadline, dateEnd) Values ('2016/02/20 12:00:00','2016/02/19 12:00:00')
    Insert Into SampleData (deadline, dateEnd) Values ('2016/02/20 12:00:00','2016/02/20 12:00:00')
    Insert Into SampleData (deadline, dateEnd) Values ('2016/02/20 12:00:00','2016/02/21 12:00:00')
    
    Insert Into SampleData (deadline, dateEnd) Values ('2016/03/01 12:00:00','2016/02/29 12:00:00')
    Insert Into SampleData (deadline, dateEnd) Values ('2016/03/01 12:00:00','2016/03/01 12:00:00')
    Insert Into SampleData (deadline, dateEnd) Values ('2016/03/01 12:00:00','2016/03/02 12:00:00')
    Locate
    
    Public oForm
    oForm = Createobject('SampleForm')
    oForm.Show()
    
    Define Class SampleForm As Form
        Height=600
        Width=800
        Add Object myGrid As Grid With ;
            RecordSource='SampleData', Height=600, Width=800, Anchor = 15
    
        Procedure Init
            This.myGrid.SetAll('DynamicForeColor', '(thisform.GetMeColor())')
        Endproc
    
        Procedure GetMeColor
            Local deadline, dateEnd, lnColor
            deadline = Ttod(Ctot('^'+SampleData.deadline))
            dateEnd  = Ttod(Ctot('^'+SampleData.dateEnd))
            Do Case
                Case m.deadline > m.dateEnd And m.deadline < Date()
                    lnColor=0
                Case m.dateEnd > Date() And m.dateEnd < Date()+7
                    lnColor=Rgb(102,205,170)
                Otherwise
                    lnColor=255
            EndCase
            Return m.lnColor
        Endproc
    Enddefine