
I have a problem with the SaveLayout / LoadLayout methods.
If I group my GridView by a DateTime column or a column which has been formatted and then save the layout, I get a null reference exception when I try to load it: "System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
At least it seems to be only when I do the mentioned grouping, but I won't say for sure that it won't happen in other cases as well. In my grid I mostly have Text columns, and the LoadLayout works fine if I group by these.
Is this a bug, or am I doing something wrong?
Regards, Jill-Connie Lorentsen
8 Answers, 1 is accepted

Thank you for writing.
I have tested a similar scenario as the described and Save/Load Layout functionality for a grouped DateTime column works as expected. However, there could be something specific in your scenario that causes the exception. Please, send me a small example project that demonstrates the problem. This will help me to investigate your case in detail and provide further assistance. I am looking forward to your project.
Greetings,
Martin Vasilev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

My SaveLayout procedure never fails and is like this:
public void setGridConfiguration(ref Telerik.WinControls.UI.RadGridView radgrid, ConfigType configType) |
{ |
string config = string.Empty; |
using (StringWriter stringWriter = new StringWriter()) |
{ |
using (XmlWriter writer = new XmlTextWriter(stringWriter)) |
{ |
radgrid.SaveLayout(writer); |
} |
config = stringWriter.ToString(); |
} |
insertConfigInDatabase( config ); |
} |
The problem arises when I try to load it the next time the grid is opened. My LoadLayout procedure is like this:
public void getGridConfiguration(ref Telerik.WinControls.UI.RadGridView radgrid, configType configType) |
{ |
string config = string.Empty; |
ServiceClient.wcfCommon Client = null; |
config = getConfigFromDatabase (configType); |
if (config != string.Empty) |
{ |
using (StringReader reader = new StringReader(config)) |
{ |
using (XmlTextReader textReader = new XmlTextReader(reader)) |
{ |
try |
{ |
radgrid.LoadLayout(textReader); |
} |
catch (Exception e) |
{ |
ErrorHandling(e); |
} |
} |
} |
} |
} |
I get an exception which is caught in the catch clause, saying ="Object reference not set to an instance of an object."
I've tried looking at the strings that are saved to and retrieved from the database, both in cases which failes and in cases where everything works fine, but I can't see anything wrong. I've also tried removing all formatting of the grid, visibility of columns etc without any luck.
I'm enclosing file dumps of what the grid looks like when an erronious layout is saved and after reload has been attempted.
By the way, I've tried creating a sample project, but haven't been able to reproduce the error...
Any suggestions are appreciated!
Regards, Jill-Connie Lorentsen
Thank you for getting back to us.
I couldn't find anything wrong in your code. I would suggest that you send us at least the stack trace of the exception. It will give us a hint about the place where we should search for an issue. If this does not help us, we will need a project where the issue can be demonstrated.
Kind regards,
Martin Vasilev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

at System.Data.Index.CompareRecords(Int32 record1, Int32 record2) |
at System.Data.Index.IndexTree.CompareNode(Int32 record1, Int32 record2) |
at System.Data.RBTree`1.SearchSubTree(Int32 root_id, K key) |
at System.Data.RBTree`1.GetNodeByKey(K key) |
at System.Data.RBTree`1.GetIndexByKey(K key) |
at System.Data.Index.RecordStateChanged(Int32 oldRecord, DataViewRowState oldOldState, DataViewRowState oldNewState, Int32 newRecord, DataViewRowState newOldState, DataViewRowState newNewState) |
at System.Data.DataTable.RecordStateChanged(Int32 record1, DataViewRowState oldState1, DataViewRowState newState1, Int32 record2, DataViewRowState oldState2, DataViewRowState newState2) |
at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Int32 position, Boolean fireEvent, Exception& deferredException) |
at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean fireEvent) |
at System.Data.DataRow.SetNewRecord(Int32 record) |
at System.Data.DataRow.EndEdit() |
at System.Data.DataRow.set_Item(DataColumn column, Object value) |
at Telerik.WinControls.Data.DataAccessComponent.EnsureIndexColumn(String columnName) |
at Telerik.WinControls.Data.DataAccessComponent.UpdateColumnDataType(GridViewDataColumn column) |
at Telerik.WinControls.UI.GridViewDataColumn.set_DataType(Type value) |
at Telerik.WinControls.Data.DataAccessComponent.EnsureColumns() |
at Telerik.WinControls.Data.DataAccessComponent.UpdateColumns(NotifyCollectionChangedEventArgs e) |
at Telerik.WinControls.UI.GridViewTemplate.UpdateColumns(NotifyCollectionChangedEventArgs e) |
at Telerik.WinControls.UI.GridViewColumnCollection.NotifyListenersCollectionChanged(NotifyCollectionChangedEventArgs e) |
at Telerik.WinControls.Data.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e) |
at Telerik.WinControls.Data.ObservableCollection`1.EndUpdate(Boolean notifyUpdates) |
at Telerik.WinControls.Data.ObservableCollection`1.EndUpdate() |
at Telerik.WinControls.UI.GridViewLayoutSerializer.ProcessListOverride(XmlReader reader, Object listOwner, PropertyDescriptor ownerProperty, IList list) |
at Telerik.WinControls.XmlSerialization.ComponentXmlSerializer.ReadElementInObject(XmlReader reader, PropertyDescriptor property, Object toRead) |
at Telerik.WinControls.XmlSerialization.ComponentXmlSerializer.ReadObjectElement(XmlReader reader, Object parentObject, Object toRead) |
at Telerik.WinControls.XmlSerialization.ComponentXmlSerializer.ReadElementInObject(XmlReader reader, PropertyDescriptor property, Object toRead) |
at Telerik.WinControls.XmlSerialization.ComponentXmlSerializer.ReadObjectElement(XmlReader reader, Object parentObject, Object toRead) |
at Telerik.WinControls.XmlSerialization.ComponentXmlSerializer.ReadObjectElement(XmlReader reader, Object toRead) |
at Telerik.WinControls.UI.RadGridView.LoadLayout(XmlReader xmlReader) |
at Modul.Fillers.RadGrid.getGridConfiguration(RadGridView& radgrid, ConfigType configType) in C:\develop\Modul\Administrator\Administrator\Fillers\RadGrid.cs:line 1143 |
This is the stack trace. In this case I've grouped by a DateTime column.
Thank you very much for your help!
Regards, Jill-Connie Lorentsen
Thank you for reporting the issue. The fix will be available in our next release. Your Telerik points have been updated.
Regards,
Julian Benkov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

Thank you!
Will the fix be available in the Q3 release?
What is the problem? I've done some more research, and now I think it has to do with my data. It seems like the columns that cause the error are all Nullable in my database. Is this correct, or am I way off?
Regards, Jill-Connie Lorentsen
The fix will be available for Q1 2010 release. For this release we will introduce the new redesigned data layer in RadGridView with more performance improvements and small memory footprint. The new data engine will have extended/native support for Nullable types, which is problematic in some cases and depend from DataView object used in current implementation of RadGridView.
Thank you for your understanding.
All the best,
Julian Benkov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.