I am pulling three coloums of data from a SQL view into my data drid Day,TimeIn,Timeout
I want to colour my datagrid rows red if timeout is null and green if both the timein, timeout have data in them.

here is my code so far, but it aint working

     Public Sub Datagridcolours()
    'Sets datagrid row colours  
    Dim cell As DataGridViewCell
    Dim CellVar As String
    For Each row As DataGridViewRow In Me.DGVClockins.Rows

        Dim x As String = row.Cells("ClockOUT").ToString
        cell = row.Cells("CLOCKOUT")
        CellVar = row.Cells("ClockOUT").ToString


        Select Case x

            Case IsDBNull(x)
                cell.Style.BackColor = Color.Red
                cell.Style.ForeColor = Color.White
        End Select

    Next
End Sub

hope someone out there can help me.
thanks in advance.

This is the code you need:

   For Each row As DataGridViewRow In dataGridView1.Rows
    Dim timeOut As Object = dataGridView1("Timeout", row.Index).Value
    Dim timeIn As Object = dataGridView1("Timein", row.Index).Value
    If timeOut Is Nothing Then
        dataGridView1.Rows(row.Index).DefaultCellStyle.BackColor = Color.Red
    ElseIf timeOut IsNot Nothing AndAlso timeIn IsNot Nothing Then
        dataGridView1.Rows(row.Index).DefaultCellStyle.BackColor = Color.Green
    End If
Next

Hope it will do any good.
bye

thanks for your help, I implimented your code but all the rows are now green.

I wanted all rows that have data in the clockin to be red, and rows that have data in clockin and data in the clockout to be green

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.