How to compare two dates in DatagridView and change color when VB.Net expires

0

My codes

Private Sub CadastroDataGridView_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles CadastroDataGridView.CellFormatting
If Me.CadastroDataGridView.Columns(e.ColumnIndex).Name = "DataGridViewTextBoxColumn15" Then
    If e.Value IsNot Nothing Then
        Dim dgvdate As Date = CDate(e.Value)
        If dgvdate < CDate(Now) Then
            e.CellStyle.BackColor = Color.Red
            e.FormattingApplied = True
        Else
            e.CellStyle.BackColor = Color.Green
            e.FormattingApplied = True
        End If

    End If
    End If

End Sub

    
asked by anonymous 28.01.2016 / 13:05

1 answer

1

It should look something like this:

For Each linha As DataGridViewRow In DataGridView_consulta.Rows
     valor_celula = linha.Cells(2).Value

     If valor_celula = "Aberto" Then
          linha.Cells(2).Style.BackColor = Color.Red
End If

Just substitute the comparison by date and put in a method being called in the load. The idea is to go through the rows of the datagrid, get the value of the cell, which is a fixed column and arrow the style of it.

    
28.01.2016 / 21:44