I have a table in a dataset with 6100 records. Customer complained of really bad performance. Timer testing revealed that it took 48 seconds to do the:
MyGrid.datasource = ds.tables("MyTable").defaultview
I tried a number of variations... having the defaultview sorted, not sorted, sorted same a the prim key, turning off syncwithcurrencymanager all to no avail. I'm at my wits end trying to figure out why this is taking so very long mostly because I don't know what the setting of the datasource for a grid actually does. Any ideas about what I should be looking for?
Thanks, Ron
Hi Ron,
It's hard to say what might be causing this without a lot more information. I can tell you that 6100 rows is not a lot and the grid should be able to handle that pretty easily. My guess is that something in your code is slowing it down.Which events of the grid are you hooking? I would pay particular attention to events like InitializeRow and InitializeLayout and make sure your code is as efficient as possible.
You might also want to try turning on Exception handling to see if any exceptions are being raised and caught. This is a common cause of performance issues.
Another thing to check is ValueLists. If you are using any in the grid, try removing them (as a test) to see if that helps.
Hi Mike,
Put some debug hooks into all my events and it was just the initializerow event firing. It's being called for each row during the "set datasource" statement. I guess I was confused because I thought that initializerow fired when the row was painted... So now I guess my question is this: Is there any way to cause initialize row to fire on initial painting of the row? Seems inefficient to initialize thousands of rows when you're looking at them 20 at a time. In initializerow I do things like "e.row.performautosize" and on some grids I load a cell based on a datatable lookup from another cell (ie: original cell has product code and I then lookup the product descr from the Products table, and also load the description in the grid. If you have to do this thousands of times before the grid displays I can understand why it took so long to load. By commenting out the initializerow a sample went from 20 secs to 250ms. Quite a difference.
I looked into loadstyle.loadondemand but that just postpones the problem (ie: hit sort and they get zapped with the wait while all rows are initialized).
Might you have a suggestion on an event other than initializerow that might be a little better to do things like performautosize and loading calculated columns?
Or it would be slick if there was a technique to do initializerow in the background (in another thread, perhaps). If this is possible I could display a "loading" msg in the corner and clear it when the initializerow completes for all the rows.... anyway I'm just brainstorming here...
I was going to suggest using LoadOnDemand. But you are right, once the grid is sorted, it has to load all the rows. There's no event that fires the first time the row paints, unfortunately. So I don't see any way around this.
Using another thread might be an option, but you have to be extremely careful about not modifying the data source bound to the grid on another thread. If you do anything to the data source that raises a notification, the grid might respond to it across threads without the proper marshalling and that could cause a problem. It sounds like this should be okay, since you are only reading data, but it's something to be aware of.