Hi
I have a datagridview with 9 Processes each process holds dates for stating and compleating a job.
When a process is Late a cell back color is set to yellow, when today is the day the same date on the cell the date gets bolded,if the date is altered by the admin the dates forecolor is red and when is compleated a date gets crossed out.
My Problem is some cells on one process have fore color is white when its set to red.

This is my code.

  Private Sub Dgv_Formate(ByVal e As DataGridViewCellFormattingEventArgs, ByVal Stat As String, ByVal processDate As Date, ByVal Extra_Days As Boolean)
        Dim Style As Font = Me.DGV_Machining.DefaultCellStyle.Font
        Dim thisdate As Date = "#12/09/2016#" 'Today()
        Dim started As New Proces
        If Me.DGV_Machining.Rows(e.RowIndex).Cells(Stat).FormattedValue = "n" And Not Extra_Days Then
            If processDate < thisdate Then
                e.CellStyle.BackColor = Color.Yellow
            ElseIf processDate = thisdate Then
                e.CellStyle.Font = New Font(Style, FontStyle.Bold)
            End If
        ElseIf Me.DGV_Machining.Rows(e.RowIndex).Cells(Stat).FormattedValue = "n" And Extra_Days Then
            If processDate < thisdate Then
                e.CellStyle.BackColor = Color.Yellow
                e.CellStyle.Font = New Font(Style, FontStyle.Italic)
                e.CellStyle.ForeColor = Color.Red
            ElseIf processDate = thisdate Then
                e.CellStyle.Font = New Font(Me.Font, FontStyle.Italic + FontStyle.Bold)
                e.CellStyle.ForeColor = Color.Red
            Else
                e.CellStyle.BackColor = Color.White
                e.CellStyle.Font = New Font(Style, FontStyle.Italic)
                e.CellStyle.ForeColor = Color.Red
            End If
        ElseIf Me.DGV_Machining.Rows(e.RowIndex).Cells(Stat).FormattedValue = "y" And Not Extra_Days Then
            e.CellStyle.BackColor = Color.White
            e.CellStyle.Font = New Font(Style, FontStyle.Strikeout)
            e.CellStyle.ForeColor = Color.Black
        ElseIf Me.DGV_Machining.Rows(e.RowIndex).Cells(Stat).FormattedValue = "y" And Extra_Days Then
            e.CellStyle.ForeColor = Color.Red
            e.CellStyle.BackColor = Color.White
            e.CellStyle.Font = New Font(Me.Font, FontStyle.Italic + FontStyle.Strikeout)
        End If
    End Sub

If I comment the line 31 the dates Show.

Seems as there are 3 factors: a 'n' or 'y' value; extra_days or not; and procesDate (<,> or =) versus thisDate.
I would suggest to you to draw a table like this one and fill in all the different possibilities. At least having a clear method to follow it'll be easier and less error prone.

  Factors:

'n'/'y'.............:............'n'......................|........'y'
procDate vs.thisDate:      <      |      =      |    >    |

extra_Days..........:  = 0 | <>0  | =0   |<>0   | = 0|<>0 |
=================================================================

Actions to take:
ForeColor...........:      |      |Red   |Red   | 

BackColor...........:yellow|yellow|yellow|yellow|
Bold................:      |      | Yes  | Yes  |

Italic..............:      |  Yes |      | Yes  |
Strike..............:

Hope this makes since. table.JPG

I hope it makes sense to you:

    Private Sub Dgv_Formate(ByVal e As DataGridViewCellFormattingEventArgs, _
                            ByVal Stat As String, _
                            ByVal processDate As Date, _
                            ByVal Extra_Days As Boolean)
        Try
            Dim YN As Int32 = IIf(Me.DGV_Machining.Rows(e.RowIndex).Cells(Stat).FormattedValue = "n", 0, 1)
            Dim extraDays As String = IIf(Not DGV_Machining.Rows(e.RowIndex).Cells(0).Value, 1, 0)
            Dim procDate As Date = DGV_Machining.Rows(e.RowIndex).Cells(1).Value
            Dim lt As Int32
            If procDate < thisDate Then
                lt = 0
            ElseIf procDate > thisDate Then
                lt = 1
            Else
                lt = 2
            End If
            Dim nAction As Int32 = YN * 6 + Extra_Days * 3 + lt
            Select Case nAction
                Case 0 : Action(e, Color.Yellow, Color.Red, False, True, False)
                Case 1 : Action(e, Color.White, Color.Red, True, True, False)
                Case 2 : Action(e, Color.White, Color.Red, False, True, False)
                Case 3 : Action(e, Color.Yellow, Color.Black, False, False, False)
                Case 4 : Action(e, Color.White, Color.Black, True, False, False)
                Case 5 : Action(e, Color.White, Color.Black, False, False, False)
                Case 6 : Action(e, Color.Yellow, Color.Red, False, True, True)
                Case 7
                Case 8
                Case 9
                Case 10
                Case 11
            End Select
        Catch ex As Exception

        End Try
    End Sub
    Sub Action(e As DataGridViewCellFormattingEventArgs, _
               bkClr As Color, _
               foreClr As Color, _
               Bold As Boolean, _
               italic As Boolean, _
               _strike As Boolean)
        Dim fnt As Font = Me.DGV_Machining.DefaultCellStyle.Font
        With e.CellStyle
            .BackColor = bkClr
            .ForeColor = foreClr
            Dim style As New FontStyle
            If Bold Then
                style = FontStyle.Bold
            End If
            If italic Then
                style = style Or FontStyle.Italic
            End If
            If _strike Then
                style = style Or FontStyle.Strikeout
            End If
            .Font = New Font(fnt, style)
        End With
    End Sub

Thanks XRJ
This works great and easear to debug when needed .
I just had to change the extradays to this IIf(Not Extra_Days, 1, 0) and fill in the other NAction values

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.