title: Populate dataGridView with a large set of results from SQL query in C# Windows Forms
body: <p>I have a <a href="http://en.wikipedia.org/wiki/Windows_Forms" rel="nofollow">Windows Forms</a> created with a dataGridView on it. I also have a long running SQL query that I am running in a <a href="http://msdn.microsoft.com/en-us/library/8xs8549b.aspx" rel="nofollow">BackgroundWorker</a> thread to populate a static datatable. </p>
  
  <pre><code>private void RunQuery_DoWork(object sender, DoWorkEventArgs e)
  {
      OdbcDataAdapter adapter = new OdbcDataAdapter(longRunningSQLQuery, datasourcename);
      adapter.Fill(results);
  }
  
  private void RunQuery_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  {
      dataGridView1.DataSource = results;
  }
  </code></pre>
  
  <p>This works perfectly fine. When I go to run the query, the UI remains responsive as the results are generated in the background... However, when it comes time to display the results in my dataGridView the window freezes if it's a large set of data. If I let it sit for a while, eventually it finishes. In my RunWorkerCompleted callback function, I call
  <code>dataGridView1.DataSource = results;</code> (results is my DataSet) and this is the part that is taking a long time.</p>
  
  <p>Is there any way I can pre-bind the dataGridView, or bind it in the backgroundworker?</p>