Note that there are some explanatory texts on larger screens.

plurals
  1. PONonblocking update to a DataGridView
    primarykey
    data
    text
    <p>I understand how to use delegates to update controls on the main control thread, works like a charm. My problem here is if I'm adding a large <code>DataSet</code> (say 2000 items) to a bound <code>DataGridView</code>, it takes 5-8 seconds for the grid to populate and during that 5-8 seconds the whole GUI is locked. How can I update the <code>DataGridView</code> such that it doesn't lock the user interface?</p> <p>To be clear, the problem isn't that I'm doing a slow query to a database and the UI is blocking on that, I already have the <code>DataSet object[]</code> and adding the array of objects to a <code>BindingList&lt;object&gt;</code> which the <code>DataGrid</code> is bound to so:</p> <pre><code>BindingList&lt;object&gt; dataProvider = new BindingList&lt;object&gt;(); DataGridView gridView = new DataGridView(); gridView.DataSource = dataProvider; // ...stuff happens... object[] source = dataSet; //of 2000 items foreach (object item in source) { //this foreach blocks dataProvider.Add(item); } </code></pre> <p>I tried various things (that I knew wouldn't work but figured I'd see) like creating a delegate that did the <code>dataProvider.Add()</code>, but that didn't matter since it still had to happen on the control thread.</p> <p>A couple good suggestions revolved around building the <code>BindingList</code> first and then setting the <code>gridView.DataSource</code>. While this works (it updates the grid instantly), the only way I see to add more data is to create another new <code>BindingList</code>, do a <code>gridView.DataSource.copyTo()</code> (to get the existing data) and add the new data on top of that, then set the <code>gridView.DataSource</code> to the new <code>BindingList</code>. This won't work for me since the objects in my list are not static, they are each uploading data to a server asynchronously, and copying them to a new <code>BindingList</code> would cause problems.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload