Hello,
I have a grid that is loading thumbnail images into cells in each row. When there are thousands of rows, performance is pretty slow. Is there a way to fill a cell or row only when it is displayed? I see there is a LoadOnDemand property for the Web grid, is there an equivalent for Win?
Can someone give any tips on how to implement something like this?
Thanks for the help!
Sean.
Mike,
The Dictionary idea is working great. Now I'm woking on the CreationFilter idea you suggested. I'm trying to follow the "HOWTO" articles on using CreationFilters, but I'm still a little lost. I created an a class that implements ImageUIElement and a class that implements IUIElementCreationFilter, but I'm still not clear on how to implement the code to get it to work. Can you help with an example (preferably VB.Net)?
Thanks,
Those are great ideas, I will look into those. But my main hope was to not load all of the images initially. The problem we're having is that we're loading all of the images, which takes time, and the user may not even look at them because the UI has multiple tabs.
I do see there is an UltraGrid.DisplayLayout.LoadStyle property. I can't just set that to LoadOnDemand?
Okay, so I assume the row of data has some key field that you are using to determine the image to display. I also assume that you are loading the entire image into memory and then creating a thumbnail version for display in the grid.
There are a couple of approaches you can take to make this more efficient.
What I would do is - create some sort of caching mechanism. You could create a class that uses a Dictionary to store the key and the thumbnail. Then whenever you need a thumbnail, you pass the key to a method on this class. The class checks the dictionary to see if it already exists and if so, returns it. If not, the class goes out and gets the thumbnail and caches the key and the image in the dictionary so that the next time you ask for it, it's much faster.
That, of course, has nothing to do with the grid, but it's an optimization technique I have used in the past.
Regarding the grid itself, I recommend that you check out the WinGrid Performance Guide. In particular, the section on Memory Usage where it talks about re-using appearances.
If that's still not good enough, then another option would be to use a DrawFilter or CreationFilter. I'd probably go with the CreationFilter. You could replace the contents of the cell with a single ImageUIElement that fills the cell and apply your image to it based on the key value.
The advantage of this approach is that you only need to draw the images for cells that are actually displayed on-screen. The down side is that you will constantly be accessing the images every time the grid paints. So if you are going to take this approach, you pretty much have to use the caching mechanism I described above or else it will likely be even slower.
So in this approach, you do not use the Appearance on the cell at all, the DrawFilter handles the drawing of the cell based on the key value.
We are looking up the images on the file system and loading them in using the cell Appearance.
Hi Sean,
Where are the images coming from? Are they stored in the data source as actual images? Is the column's DataType Image? Or are the images coming from some sort of lookup and you using the Appearance on the cell to supply the image?