I've got an SQL query that returns hundreds of rows, and I need to add them to a WinForms DataGrid in a way that will still allow the user to view/scroll the DataGrid as the rows are added.
Currently I'm using a BackgroundWorker thread to execute the SQL statement and loop through the rows in a DataReader, before using Control.BeginInvoke to pass each new row back to the UI thread where it is added to the DataTable that's bound to the DataGrid. This isn't really having the desired effect (it takes a little while to update the DataGrid, and then after it does one update the UI becomes unresponsive).
Is there a way to do what I want, and if so how?
Edit: I've added a thread.sleep to the worker thread as it loops through the datareader, which stops the UI from becomming unresponsive after the first update, but it's still not as responsive as I would like it to be (scrolling is a bit jumpy as adding a row in the ui thread seems to steal focus).