title: How to get DataGridView Row back color to change
body: <p>I have a DataGridView control with</p>
  
  <pre><code>dgridView.DataSource = QueryCustomers(LastName)    // return IList from LINQtoSql
  </code></pre>
  
  <p>I am using the following to alter Row BackColor:</p>
  
  <pre><code>Private Sub dgridView_OnPrePaint(ByVal sender As System.Object, ByVal e As DataGridViewRowPrePaintEventArgs) Handles dgridView.RowPrePaint
  
      Dim dgridRow As DataGridViewRow = dgridView.Rows(e.RowIndex)
  
      Select Case dgridRow.Cells("Status").Value
          Case "Alpha"
              dgridRow.DefaultCellStyle.BackColor = Color.LightGreen
          Case "Beta"
              dgridRow.DefaultCellStyle.BackColor = Color.LightGreen
          Case "Terminated"
              dgridRow.DefaultCellStyle.BackColor = Color.Salmon
          Case Else
              If currentColor = Color.White Then
                  dgridRow.DefaultCellStyle.BackColor = Color.Silver
              Else
                  dgridRow.DefaultCellStyle.BackColor = Color.White
              End If
  
              currentColor = dgridRow.DefaultCellStyle.BackColor
      End Select
  End Sub
  </code></pre>
  
  <p>This seems to work except that with certain queries, the DataGridView will continue to flicker until I edit a row and save. Editing is performed by double-clicking one of the rows causing a WinForm to display over the main form containing the DataGridView. Once I save the data, and data changes in the data grid, the flickering stops. </p>
  
  <p>Is there a better way to color the rows? I don't want to iterate the DataGridView everytime something changes. It seems like subscribing to the RowPrePaint event would be the thing to do. Do I need to subscribe to the RowPostPaint?</p>
  
  <p>NOTE: answers can be C# or VB.Net.</p>