title: C# DataGridView doesn't show Scrollbars when filling from Task
body: <p>I'm currently seeing the following problem:
  I have a DataGridView that is filled by a <strong>Task</strong> running in the background. After the task is finished, the scrollbars and cells aren't shown properly in the DataGridView somehow... After resizing the dialog to fullscreen mode (maximized), the scrollbars are shown properly... Whenever the resizing is done the other way (to minimized), the scrollbar fails again... Any ideas here? Is there any refresh event I can trigger from the Task to readjust the scrollbars and cells?</p>
  
  <p>**Additional information: ** The DataGridView is packed onto a TableLayoutPanel with Dock = Fill.</p>
  
  <p><a href="https://i.stack.imgur.com/avyNh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/avyNh.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/DHvdy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DHvdy.png" alt="enter image description here"></a></p>
  
  <p><strong>Edit:</strong>
  The data loading is done via</p>
  
  <pre><code>private void TryLoadData()  
  {
      try
      {
          LoadData();
      }
      catch (Exception ex)
      {
          //Just some error logging
          _log.Error(ex);
          _errorHandler.Show(ex);
      }
  }
  
  private void LoadData()
  {
      ClearRows();
      //Loading from database
      var data = _databaseAdapter.Get&lt;Data, bool&gt;(x =&gt; !x.Deleted);
      foreach (var singleDatum in data)
          LoadDataRowToDataGridView (singleDatum);
  }
  
  private void ClearRows()
  {
      this.UiThreadInvoke(() =&gt; { DataGridView.Rows.Clear(); });
  }
  
  private void LoadDataRowToDataGridView(Data singleDatum)
  {
      this.UiThreadInvoke(() =&gt; { DataGridView.Rows.Add(singleDatum.Id, singleDatum.Name); });
  }
  </code></pre>
  
  <p><strong>Started via:</strong></p>
  
  <pre><code>new Task(TryLoadData).Start();
  </code></pre>
  
  <p><strong>UiThreadInvoke:</strong></p>
  
  <pre><code>using System;
  using System.Windows.Forms;
  
  namespace UIExtensions
  {
      public static class UiThreadInvokeExtension
      {
          public static void UiThread(this Control control, Action code)
          {
              if (control.InvokeRequired)
              {
                  control.BeginInvoke(code);
                  return;
              }
              code.Invoke();
          }
  
          public static void UiThreadInvoke(this Control control, Action code)
          {
              if (control.InvokeRequired)
              {
                  control.Invoke(code);
                  return;
              }
              code.Invoke();
          }
      }
  }
  </code></pre>