Coloring Gridview line

Asked

Viewed 18 times

-1

This is my code:

Private Sub ListaVeiculos_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles ListaVeiculos.CellFormatting
    For i As Integer = 0 To ListaVeiculos.Rows.Count - 1
        If ListaVeiculos.Rows(i).Cells(("DateFimVig")).Value.ToString = "19/02/2020" Then
            ListaVeiculos.Rows(i).DefaultCellStyle.ForeColor = Color.Blue
        End If
    Next

End Sub

It’s not working. It’s not coloring anything.

  • ForeColor sets the text color. You have tried using BackColor?

  • Already. It doesn’t work.

  • Have you checked if that parole is being True to change the value?

  • Coincidentally this problem is only with the date column. When I use other columns with common names it works.

1 answer

0

I managed to solve. I’ll leave the code in case someone needs to color lines from Gridview using as condition dates:

Private Sub ListaVeiculos_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles ListaVeiculos.CellFormatting
    Dim dt As String
    Dim thd, nw As Date

    nw = Date.Now

    nw = nw.AddDays(30)

    For i As Integer = 0 To ListaVeiculos.Rows.Count - 1
        dt = ListaVeiculos.Rows(i).Cells("DateFimVig").Value.ToString

        If dt <> "" Then
            thd = Date.Parse(dt)
        End If

        If thd.Date <= nw.Date Then
            ListaVeiculos.Rows(i).DefaultCellStyle.ForeColor = Color.Red
        End If

    Next

End Sub

Browser other questions tagged

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