The purpose of this article is to provide some general programming practice guidelines and troubleshooting tips to improve performance when using the UltraWinGrid control. Not all of the tips provided here will apply to every application, but it should help with the most common performance issues a developer is likely to encounter.
If you are concerned about reducing the amount of memory used by the grid, then there are several important things you can do to reduce it.
The grid does not create UltraGridCell objects for every row of data. Cells are only created as neccessary. So whenever possible, you should avoid accessed a cell. For example, suppose your code is using the InitializeRow event of the grid in order to calculate a total. For example:
}
This code references three cells in each row of the grid, thus creating a lot of objects which are potentially unneccessary. This can be avoided using methods on the row to deal with cell values, rather than the cell objects themselves. Like so:
By using the GetCellValue method, we can eliminate 2 cells per row in this example and save memory.
Another common use for the InitializeRow event is to apply an appearance to a cell based on the Value of that cell. Applying an appearance to a cell requires getting a reference to the UltraGridCell, so that is unavoidable. But you can save memory by re-using the same appearance object for multiple cells. Suppose, for example, that you want to change the ForeColor of a cell to red for negative numbers and black for positive numbers. You might do something like this:
This code will create a cell for every row. That is unavoidable, since the cell must be created in order to have an Appearance. The bigger problem here is that the Appearance property on the cell is lazily created. That means that we are not only creating a cell for each row, but a new Appearance object for each row. And since there are only two possible colors, we end up creating a large number of identical appearance objects.
A better way to do this is to create the Appearances we need up front and then re-use the same appearance wherever it is needed.
Another benefit to this approach is that you can change the appearance everywhere en masse. For example, suppose your users want to use Green instead of Black for positive appearances. You could, at run-time, set the ForeColor of the “Positive” Appearance object, and every cell in the grid that was using that appearance would update automatically.
Mike Saltzman"]set MaxBandDepth to a more reasonable number. Very few users will find it useful to drill down into the data 100 levels deep
I agree this is an unreasonable number. In fact, I have had more lockups in Visual Studio from this setting than anything else. Its okay if you catch it, but if you modify your business entities after the fact you may find yourself unable to open your form in the designer.
Since this is such an unreasonable number, is there any way the default can be changed to 5 in a future release?
Hi,
We could probably change the default to a more reasonable number, but I doubt it would help much. The problem is that it's really hard to come up with a number that is reasonable in all cases. You suggested 5 here, but I'm sure there are applications that use more than 5 levels of band depth and work perfectly fine. So changing the default to 5 would cause those applications to suddenly stop showing any data beyond the 5th level.
The level of depth that you can use depends on a wide range of factors like what kind of data source you are using and the processing power of your machine. On some machines with some data sources, a setting of 10 or even 20 might work fine, whereas on other machines, 8 would be too high.
We would probably be justified in setting the default to something like 20 or 30. But this could still cause problems and break existing applications for some users. And chances are, it won't help much. Since the performance issues increase geometrically, once you cross the threshhold by even 1 or 2 levels, you're pretty much doomed.
I'm using Infragistics 2009 volume 1 which I believe is the latest, although the original install on this workstation was 2008 v1 so the preset location could be based on that version.
You can put your presets into any folder you wish, but when you create the preset you have to be running as administrator or the designer crashes. I'm using Vista SP1 and Visual Studio 2008 sp1.
jbailey@baileysw.com said:It would be nice if the presets weren't in the program files directory
What version of the grid are you using? I could be wrong, but I think the most recent versions of NetAdvantage install the presets somewhere else.
Also, I'm pretty sure if you go to the Options dialog in the Presets section of the grid designer, there's an option there to add your own custom folders to the list of where the grid designer searches for presets.
That was exactly what I was looking for. It would be nice if the presets weren't in the program files directory so that I didn't have to launch as administrator in Vista to edit them (it crashes the designer if VS isn't launched as admin), but once set it does exactly what I needed.
Thanks!
Well, it is true that you learn something new every day. I did not know about presets. My comment above was really a design time thing to avoid the situation where opening a form that has recursive references causes VS to crash or other bad things to happen. Sounds like the presets would do exactly that.
Thanks
Neil
Hi Neil,
Well, there's no way we could create a machine or global default for run-time. But you could set this up yourself so that all new grids created at design-time have a setting of your choice using Presets.
If you click the Start button on any grid on a form and go to the Presets Manager, there's a checkbox under the presets list that says "Apply this Preset to grids created at design-time."
So what you can do is create a Preset with all of the settings that you want new grids to have and check that checkbox in the designer. Every time you place a new grid on a form, it will load the settings from that preset automatically. MaxBandDepth is one of the available properties on a Preset.