Hi
We have a winforms project with wingrid.
I would like to emulate the behaviour of SQL Server management studio where upon executing the query, the results start filling in instantaneously and the process continues until all results have been fetched. This way the user doesnt have to wait at all.
Kindly advise whats the best way to achieve above.
Many Thanks
Abhishek
Hi Abhishek,
Yeah, you have to be very careful about threading and databinding. They don't mix well. The grid, BindingManager, and DataSource perform all sorts of communication behind the scenes and you don't have any control over any of it. So it's impossible to properly marshal the data across threads.
Hi Mike
Many thanks.
As usual, you have nailed it.
As soon as we moved the code that was updating the dataset to the same thread as the wingrid, it all started working very well.
Best Regards
Sure, if you could post a small sample project that demonstrates the exception, I'd be happy to take a look. Assuming I can run the sample, access the data, and reproduce the exception, I should at least be able to tell you why it's happening.
My best guess right now is that this is a threading issue. Are you using multiple threads here? Is your data source, or the code that is accessing the data on a separate thread? Because that's the only reason I can see why the grid would be getting out of synch with the data source like this call stack would seem to indicate.
In this case, we are using the grid only to display data - hence editing state is not required. We can save the selection and scroll position before loading additional data and then reselect later. Hence usability does not seem to an issue.
Basically we plan to load data from a web service and the network speeds may not be all that good. The app needs to feel responsive and so this is sort of a requirement.
Would you like a small sample where you can see whats happening and provide a workaround ?
Regards
Hi Abishek,
Well, it's hard to say exactly what's happening here without knowing exactly how you are loading your DataSet. But my guess is that you probably can't bind the DataSet directly to the grid.
The DataSet/DataTable class doesn't have any support for loading data on-demand. It expects to have all of the data at once. Of course, you could create your dataset and only load up some rows and the load more rows in chunks by doing SQL queries, but this means that the grid will get a constant stream of notifications that new data is being added and the grid will be unusable in such a case because every time it gets a notification, you may lose the selection, editing state, and scroll position of the grid.
If you are loading your data on-demand, then you really need to bind the grid to an UltraDataSource as in the "Virtual Mode Sample." The way this works is that you can tell the UltraDataSource the total number of rows in your data source so that the grid's vertical scrollbar will know the range to display. Then the UltraDataSource will fire events to let you know when it needs data and you respond to those events by getting the data for the requested rows. How you get the data is up to you, but presumably, you would check your DataSet/DataTable to see if it already has the necessary rows in memory, and if not, load them at that time.
It's pretty tricky and the DataSet really isn't designed for this kind of scenario. Personally, I'd recommend giving your users come kind of query interface and let them bring back a small subset of records they need to work with instead of the entire data set all at once. No human user is going to be able to effectively work with a data set that's so large it causes is a noticeable delay in retrieving it, anyway.