title: C# DataGridView AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
body: <p>I am displaying a table with up to 100,000 rows in a DataGridView. The table has one column which contains large strings. I found out that setting <code>AutosizeMode</code> to <code>AllCells</code> causes the application to freeze for a long time while its computing the required width.
  As a compromise, I set the Autosize mode to DisplayedCells. 
  I then bound a method to the dataGrid's scroll event:</p>
  
  <pre><code>public void MethodThatBindsDataToTheDatagridview(DataTable table)
  {
     dataGrid.Source = table;
     dataGrid.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
     dataGrid.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  }
  
  public void DataGridScroll(object sender, ScrollEventArgs e)
  {
     ((DataGridView)sender).Update();
  }
  </code></pre>
  
  <p>I also tried the same with <code>Refresh</code> method. My expectation is that the DataGrid will set the columns width according to the displayed rows. However, this happens only once when the table is loaded, but the scroll event does not trigger a change in the columns width.</p>