In our GridControl derived class, we have a method that sets a lot of the grid styles. We''ve added "Theming" to our application which is kind of like skins, and we''ve added support so that the "theme" can change while the application is running.
To support this, I have to go back and re-set a bunch of the style values.
In the code, I''m setting the styles for the Column Headers. The code section where I''m having trouble is as follows:
this.BaseStylesMap["Column Header"].StyleInfo.Borders.Top = nullBorder_;
this.BaseStylesMap["Column Header"].StyleInfo.Borders.Left = nullBorder_;
this.BaseStylesMap["Column Header"].StyleInfo.Borders.Bottom = headerBorder_;
this.BaseStylesMap["Column Header"].StyleInfo.Borders.Right = headerBorder_;
this.BaseStylesMap["Column Header"].StyleInfo.CellAppearance =
this.BaseStylesMap["Column Header"].StyleInfo.ReadOnly = true;
this.BaseStylesMap["Column Header"].StyleInfo.Font = new GridFontInfo(lastCachedTheme_.Fonts[DEFAULTGRIDFONT]);
This code has been there for months and been working perfectly during intitialization of hte grid.
The problem is when we call it the second time (when a theme changes and the grid is already displayed), the call to set the font throws a null reference exception.
I''ve tracked it down to Syncfusion.Styles.StyleInfoStore.HasValue(StyleInfoProperty sip)
Is there some reason that this can''t be done the second time around?
BTW, lastCachedTheme_.Fonts is returning a Font as you might suspect.
System.Drawing.Font is internaly in .NET Framework a wrapper around a GDI font handle and such handles are limited in quantity,
So, I do suspect that in your case the amount available font handles gets low and then the GC deletes those objects. That''s why you get a null reference when you access that font after the inner handle was released.
You should not keep the Font object around. Instead copy its information to some kind of FontInfo structure where you hold the settings of the font and then create the font only when you need it and dispose it afterwards.
ADAdministrator Syncfusion Team February 3, 2005 07:01 AM
I''m fairly certain that''s not the problem.
The theme architecture handles caching of fonts and our application uses only 3 or 4 fonts total. Almost everything uses Tahoma 8.25 normal.
In this particular case, I''m setting exactly the same font. So the exact same Font object is used in both calls, but I''m creating a new GridFontInfo() object.
StyleInfoStore.HasValue() is throwing the exception. The code is:
public virtual bool HasValue(StyleInfoProperty sip)
return sip.BitVectorIndex < include.Length &&
So I''m fairly certain this means that sip is null, include is null, or the include indexer is doing something thats referencing a null object. I haven''t traced into it yet. I''m having a bit of trouble doing that, but will pursue that this morning.
ADAdministrator Syncfusion Team February 3, 2005 07:04 AM
Sorry, just to clarify on the theming. The theming architecture caches the font. That means everywhere in our application, we''re re-using the exact same Font object for every occurence of Tahoma 8.25 normal, for example. I just checked in the debugger and the cache only has 3 fonts in it, so that''s all our application is using for its entire lifetime.
ADAdministrator Syncfusion Team February 3, 2005 07:35 AM
Is it possible the GridFontInfo or maybe in some other place, that the Grid is disposing of our cached font? That would certainly be a problem for us.
I assumed it wouldn''t since the GridFontInfo isn''t itself a font, but more of a font descriptor.