views:

57

answers:

2

I am working on application which uses a DataGridView control. Since there is a lot of data I use the VirtualMode to use paging, but even with this feature this take a while to update DataGridView. So I created a control which spins and entertain an user. Unfortunately there are some issues with this solution, namely when the entertainment control spins the UI Thread does handle any of requests from it because it's so busy with this DataGridView.

What should I do to access the UI Thread even if it is so busy? How do you do to "entertain" an user when you use the DataGridView or is there any main to prevent UI Thread from blocking by DataGridView?

btw. I know that Application.DoEvents probably could help, but I prefer not to use it.

A: 

Drop the priority of the DataGridView thread relative to the UI one or just throw in the occasional Thread.Sleep in the DGV data load function.

Combined with a little tuning of your page sizes that should sort it.

FixerMark
Hi, thanks for the answer, could you explain what you mean saying "Drop the priority of the DataGridView thread relative to the UI one", how can I achieve this effect?
Jarek
A: 

Hi Jarek,

I'm not sure what your implementation looks like, so forgive me if you already know this: Setting the VirtualMode property to "true" doesn't make the DataGridView automatically populate itself via just-in-time loading. Rather, it just gives you as the developer the ability to do so. If you're using virtual mode but still populating the entire thing at once, then you really aren't gaining anything. Instead you'll have to implement your own paging algorithm. This is actually pretty easy to do. Please take a look at this MSDN topic for an example. Hopefully that helps!

Kevin D.
Hi Kevin, Thanks for the answer. I didn't specify this in the main post, but I actually referred to this MSDN page. So, I introduced a cache and I set RowCount property to small pieces of data. This helped but the Form which contain the DataGridView control still gets frozen or blocked. This is due to the fact that the DGV control literally occupied Main / UI Thread in 100% percent. Best Regards Jarek
Jarek
Hi Jarek, would it be possible for you to post a code snippet? I use the DGV to display large amounts of data in virtual mode without issue. While the DGV does have some other bugs, I'm not sure how it could completely tie up the UI thread unless there was some heavy data binding happening without the layout being suspended.
Kevin D.