title: Coloring Groups of Cells based on Content in Datagridview C#
body: <p>I am working with a rather large datagrid bound to a Datatable.  My goal is to color groups of cells based on data in the cell.  </p>
  
  <p>I want the datagrid to color all cells that contain a value, and then switch colors when it detects a new value and repeat this throughout the table.  </p>
  
  <p>Here's an example of what I'm working with in the table:</p>
  
  <pre><code>    Contract ID:
      123456 //Top of the contract, color all cells in the contract blue
      123456 //blue
      123456 //blue
      123456 //blue
      456789 //New contract, color all these cells green
      456789 //green 
      456789 //green
      987654 //Another new contract color all these blue (or another color) again
      etc... 
  </code></pre>
  
  <p>I have tried something similar to below but to no avail...</p>
  
  <pre><code>for (int i = 0; i &lt; myDataGridView.Rows.Count; i++)
      {
           if (i &gt; 0)
           {
               if (myDataGridView.Rows[i].Cells["contract_id"].Value != myDatagridView.Rows[i-1].Cells["contract_id"].Value)
               {
               myDataGridView.CurrentRow.Cells["contract_id"].BackColor = Color.Blue;
               }
           }
      }
  </code></pre>
  
  <p>I am not sure where to begin with this, I have tried looping over the rows and checking the values, but this ends up killing performance and speed and doesn't give me the result I am looking for.  Any suggestions would be greatly appreciated.</p>