Change color of a Row when VB expires . Net

Asked

Viewed 174 times

3

I have a database with the following tables: Data Emissão and Data Expira.

So I want that when the date of Data expira is equal to or greater than Data Emissao, to row change color to Vermelho and when it is 1 month to reach the date change color to Amarelo.


My code

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
  • 1

    With the following columns no tables, right?

  • 1

    Post the complete tables...

  • 1

    Please show your code, highlight what matters to doubt and say what you have tried.

1 answer

2

I didn’t test it, but it should work:

Dim data_addmes As Date = Date.Now.AddMonth(1)
Dim data_expira As Date = dgvRow.Cells("Data_expira").Value
Dim data_emissa As Data = dgvRow.Cells("Data_Emissao").Value

If data_addmes >= data_expira Then
    dgvRow.DefaultCellStyle.BackColor = Color.Yellow
Else If data_expira >= data_expira Then
   dgvRow.DefaultCellStyle.BackColor = Color.Red
End If
  • Post your code I can improve my answer

Browser other questions tagged

You are not signed in. Login or sign up in order to post.