title: (datagridview) update a row's font color base on a column value
body: <p>I'd like to ask how a row auto update its font's color base on a column's value in <code>dataGridView</code>.</p>
  
  <p>For example, a table has 4 columns that are: <code>id, name, rentPayMent and check</code>.</p>
  
  <p>Check for each row to see if any of the value of <code>check == 0</code> 
  If yes, then this row's font <code>color = red</code>  Else <code>do nothing</code></p>
  
  <p>at the movement, i use the code as following, but it bring out error with </p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object,System.NullReferenceException was unhandled</p>
  </blockquote>
  
  <pre><code>private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
  {
      foreach (DataGridViewRow row in dataGridView1.Rows)
      {
          if (row.Cells[3].Value.ToString() == "0") //**Object reference not set to an instance of an object**
          {
              row.DefaultCellStyle.BackColor = Color.Red;  //then change row color to red
          }
      }
  }
  </code></pre>
  
  <p><strong>Thanks for all, i got the solution already.</strong></p>
  
  <pre><code>    private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
      {
          if (dataGridView1.Rows[e.RowIndex].Cells[3].Value != null &amp;&amp; !string.IsNullOrWhiteSpace(dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString()))
          {
              if (dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString().Trim() == "0")
                  dataGridView1.Rows[e.RowIndex].DefaultCellStyle = new DataGridViewCellStyle { ForeColor = Color.Red };
          }
          else
          {
              dataGridView1.Rows[e.RowIndex].Cells[3].Style = dataGridView1.DefaultCellStyle;
          }
  
      }
  </code></pre>