I'm using a DataGridView control and populating it's row collection programatically. Whenever a button is clicked, it clears the DataGridView row collection and then populates it again with new rows depending on user criteria.
Sometimes only 1 or a few rows will populate the control, and that's fine, but sometimes it can be a couple of hundred rows, and when this happens, the form freezes for a number of seconds or even more than a minute as the rows are added to the collection and the form refreshes.
This is unacceptable. So I've tried a whole lot of different methods to make the form paint itself even as the rows are being populated. Problem is, none of these methods work correctly. The problem that arises 100% of the time is that the scrollbars are "frozen", unusable, for the DataGridView control whenever I try to populate the rows from a background thread instead of from the main UI thread.
I don't really understand why this is happening and I've scoured google for 2 hours now and tried so many different things invluding Invoke and BeginInvoke and a number of other things, and nothing has solved the issue.
SUMMARY: The scrollbars work perfectly fine after the rows are all finished being added if I am doing it NOT in a background thread. But that presents the problem of the UI freezing until all rows are added. So if I put the row population in the background thread, it solves the UI freezing problem EXCEPT for the scrollbars on the DataGridView control, which are indefinitely frozen or not even visible.
So to be a bit more specific, I tried this:
private void cmdSearch_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(thread));
t.Start();
}
void thread()
{
resultsVolumeSearch.Rows.Clear();
List<Volume> volumes = Volume.SearchVolumes(txtQuery.Text, 0);
foreach (Volume v in volumes)
{
Image img = DownloadImage(v.image);
resultsVolumeSearch.Rows.Add(new object[] { img, v.id, v.name, v.info, v.details, v.count });
}
}
And I've got
CheckForIllegalCrossThreadCalls = Falseset for the form.
So I really need to know what I can do to get my DataGridView rows to update without freezing my UI during the process and without messing up with scrollbars after it's done.
Any suggestions??? Thanks in advance.
This post has been edited by callahan09: 30 April 2011 - 06:47 PM

New Topic/Question
Reply




MultiQuote





|