title: C# Datagridview set column width to prefered size when datagrid is on fill
body: <p>I have a datagridview, that is set to "Fill" because that way you have no ugly blank spots. Now I want to resize 2 columns so the content is fully shown.</p>
  
  <p>With this piece of code I can change the width of one column:</p>
  
  <pre><code>DataGrid.Columns[1].Width = DataGrid.Columns[1].GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true); 
  </code></pre>
  
  <p>But when I add it for the other cell that needs to be resized</p>
  
  <pre><code>DataGrid.Columns[5].Width = DataGrid.Columns[5].GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true);
  </code></pre>
  
  <p>It overrides the first one, so only the last cell will be resized correctly.</p>
  
  <p>Does anyone have an idea on how to fix this?</p>