title: DataGridView call CellFormatting only once
body: <p>I'm creating a dynamic DataGridView from a returned DB table. I need to change some cells to Red based on the value. I assigned a function to the <strong>CellFormatting</strong> event, but the function get called every time the user clicks on any cell/row (which slows down the form).</p>
  
  <p>I would like to execute the function only on load. </p>
  
  <p>I tried to set the style by looping the table, but the back color didn't change. I got it to work only when using the CellFormatting event.</p>
  
  <p><strong>the code I have:</strong></p>
  
  <pre><code>this.dgv.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.Dgv_CellFormatting);
  </code></pre>
  
  <p>and in the function I change the color</p>
  
  <pre><code>    private void Dgv_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
      {
          if (e.Value != null)
          {
              if (e.ColumnIndex == 0)
              {
                  if ((int)e.Value &gt;= 5)
                  {
                      e.CellStyle.BackColor = Color.Red;
                  }
              }
          }
  
      }
  </code></pre>