title: DataGridView checkbox column "select all" performance
body: <p>I have a DataGridView with a checkbox column. I'm trying to create a select/deselect all button. The code for changing the values is easy enough, but the performance is horrendous.</p>
  
  <pre><code>for (int i = 0; i &lt; dgv.RowCount; i++)
  {
      dgv.Rows[i].Cells["Selected"].Value = _selectAll;
  }
  </code></pre>
  
  <p>_selectAll is simply a toggle bool variable. Is there a better way to do this where the performance is fast? I've tried changing the value in the underlying DataTable as well. It still takes several seconds for just a few hundred rows, but most work will be done on  thousands of rows.</p>
  
  <p><strong>EDIT &amp; SOLUTION (2011/10/4)</strong></p>
  
  <p>The main problem was in the DGV properties. Once I set,</p>
  
  <pre><code>dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
  </code></pre>
  
  <p>performance improved dramatically (per <a href="http://msdn.microsoft.com/en-us/library/ha5xt0d9.aspx">MSDN DataGridView Performance</a>).
  The solutions suggested as of this edit would also improve performance slightly.</p>