title: Is there a way to force a DataGridView to fire its CellFormatting event for all cells?
body: <p>We use the CellFormatting event to colour code cells in various grids all over our application.</p>
  
  <p>We've got some generic code which handles export to Excel (and print) but it does it in Black &amp; White. Now we want to change this and pick up the colour from the grids.</p>
  
  <p>This <a href="https://stackoverflow.com/a/10616569/180430">question &amp; answer</a> has helped (and it works) ... except there's a problem with larger grids that extend beyond a single screen. The portions of the grid which haven't yet been displayed on screen are (logically) never getting their CellFormatting code fired, and so their underlying colour never gets set. As a result, in Excel, the colour coding <em>fizzles out</em> half way down the page.</p>
  
  <p>Seems there are three solutions:</p>
  
  <p>1) Tell the user he has to scroll to all parts of the grid before doing an Export to Excel. <strong>Ha! Not a serious solution</strong></p>
  
  <p>2) Programmatically scroll to all parts of the grid before doing an Export to Excel. <strong>Only slighly less horrible than (1)</strong></p>
  
  <p>3) In our Export to Excel code, fire something at the top which tells the DataGridView to paint/format its entire area e.g.</p>
  
  <pre><code>  MyDataGridView.FormatAllCells()
  </code></pre>
  
  <p><strong>Is there something that does something like this???</strong></p>
  
  <p>Oh, and there is a fourth option but this will involve touching a massive amount of existing code:</p>
  
  <p>4) Stop using CellFormatting event, format the cells at load time. Problem with this is we'd have to retool every grid in our application since CellFormatting is the way we've done it since year dot.</p>