We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Changing BaseStyle in Realtime

Greetings, Excuse my post if it seems a bit simplistic, I''m new to this toolkit. My application sets up a number of BaseStyles that represent my formatting options. The application runs fine the first time through the configuration code block and generates the right StyleInfo (as I can see it displaying properly in the application). Later, I change some "configurable" items and try to apply them to the base styles and I get a NullReferenceException. I cant see that I''m doing anything odd, but here is the code block (it is used the first time [which works] and second time [which fails]). PreferencesModel model = AppMain.AppPreferencesModel ; PreferencesModel.FormatState format_state = model.Format ; m_dataGrid.BeginUpdate() ; foreach( DictionaryEntry entry in format_state.Attributes ) { Rule rule = entry.Key as Rule ; FormatAttributes attributes = entry.Value as FormatAttributes ; Font font = attributes.Font ; string ident = rule.m_filter.Ident ; GridBaseStyle base_style = m_dataGrid.BaseStylesMap[ ident ] ; GridFontInfo font_info = new GridFontInfo() ; font_info.Bold = font.Bold ; font_info.Italic = font.Italic ; font_info.Facename = font.FontFamily.Name ; font_info.Size = font.Size ; font_info.Strikeout = font.Strikeout ; font_info.Underline = font.Underline ; base_style.StyleInfo.BeginUpdate() ; base_style.StyleInfo.BackColor = attributes.Background ; base_style.StyleInfo.TextColor = attributes.Foreground ; base_style.StyleInfo.Font = font_info ; base_style.StyleInfo.EndUpdate() ; } m_dataGrid.Model.ResetVolatileData() ; m_dataGrid.EndUpdate() ; Here is the exception: System.NullReferenceException: Object reference not set to an instance of an object. at Syncfusion.Styles.StyleInfoStore.get_IsEmpty() at Syncfusion.Styles.StyleInfoBase.get_IsEmpty() at Syncfusion.Styles.StyleInfoIdentityBase.GetBaseStyleNotEmptyExpandable(IStyleInfo thisStyleInfo, StyleInfoProperty sip) at Syncfusion.Windows.Forms.Grid.GridStyleInfo.get_GdipFont() at Syncfusion.Windows.Forms.Grid.GridStaticCellRenderer.OnDraw(Graphics g, Rectangle clientRectangle, Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridCellRendererBase.Draw(Graphics g, Rectangle cellRectangle, Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridStaticCellRenderer.Draw(Graphics g, Rectangle cellRectangle, Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridControlBase.OnDrawItem(Graphics g, Int32 rowIndex, Int32 colIndex, Rectangle rectItem, GridStyleInfo style) catched at Syncfusion.Windows.Forms.Grid.GridControlBase.OnDrawItem(Graphics g, Int32 rowIndex, Int32 colIndex, Rectangle rectItem, GridStyleInfo style) in :line 0 catched at Syncfusion.Windows.Forms.Grid.GridControlBase.OnDrawItem(Graphics g, Int32 rowIndex, Int32 colIndex, Rectangle rectItem, GridStyleInfo style) in :line 0

2 Replies

AD Administrator Syncfusion Team March 3, 2004 11:18 AM

Instead of GridFontInfo font_info = new GridFontInfo(); try using GridFontInfo font_info = base_style.StyleInfo.Font; Ie., modify the fontinfo object present in the basestyle, and not set a new (almost empty with a some default properties set) that loses some ID settings.


AJ Aaron Jackson March 3, 2004 11:42 AM

Thank you for the quick response, that fixed my issue.

Loader.
Live Chat Icon For mobile
Up arrow icon