change data grid view row colour depend upon the value

vb.net

Solution

Try this

 Private Sub DGVDashBoard_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DGVDashBoard.CellFormatting
            Dim drv As DataRowView
            If e.RowIndex >= 0 Then
                ' Add Your condition here ignore following
                If e.RowIndex <= ds.Tables(0).Rows.Count - 1 Then
                    drv = ds.Tables(0).DefaultView.Item(e.RowIndex)
                    Dim c As Color
                    If drv.Item("Value").ToString = "1" Then
                        c = Color.Red                        
                    End If
                    e.CellStyle.BackColor = c
                End If
            End If
        End Sub

Let me know if this doesn't work.

Problem

I have a DataGridView like this: I am binding the DataGridView like this: ``` Dim cmd As New SqlCommand("DashBordFetch", con.connect) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.Add("@locid", SqlDbType.Int).Value = locid da.SelectCommand = cmd da.Fill(ds) DGVDashBoard.DataSource = ds.Tables(0) ``` I want to my DataGridView to have a red row color when the Value is 1. How can I do that? I am working in VB.NET. I have tried the code in one of the answers provided, it looks like this:

Original source