I have windows forms created using dataGridView. I also have a long SQL query that I run in the BackgroundWorker thread to populate a static datatable.
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; }
This works great. When I go to run the query, the user interface remains responsive as the results are generated in the background ... However, when it is time to display the results in my data file, the window freezes if it contains a large data set. If I let him sit for a while, in the end he ends. In my RunWorkerCompleted callback function, I call dataGridView1.DataSource = results; (the results are my DataSet), and this is the part that takes a lot of time.
Is there any way to pre-bind the dataGridView or bind it to the desktop?
source share