Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
60
Error when saving Grid DisplayLayout
posted

Hi

I'm just upgrading our software from Infragistics EIGHT.THREE to the latest version (16.2) and I'm running into a couple of issues when testing the software, most of the conversion has gone much better than expected. Please note I'm new to Infragistics so not sure of the correct way to do things... Anyway one issue I'm having is that when a WINFORM is loading we do the following to load up the grid layout in the form constructor, I've noticed they are also adding on en EditorComponent:

InfragisticsUtils.LoadLayout(ug);  // Loads the layout of the grid from a LYT file.

ug.DisplayLayout.Bands[0].Columns[SalesOrderConstants.ColumnOrderNumber].EditorComponent = OrderNumberComboEditor;

Then later when the user closes the form - in the DISPOSE() method, we save the grid layout using:

var ser = new GridLayoutSerializer { { name, grid.DisplayLayout } };
ser.SaveLayoutToFile(name, path);

on the ser.SaveLayoutToFile line an exception is thrown:

Object reference not set to an instance of an object.

at Infragistics.Win.Utilities.FindContainedControlByName(Control container, String controlName)
at Infragistics.Win.Utilities.FindContainedComponentByName(Control container, String componentName)
at Infragistics.Win.UltraWinGrid.UltraGridColumn.get_EditorComponent()
at Infragistics.Win.UltraWinGrid.UltraGridColumn.System.Runtime.Serialization.ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at Infragistics.Win.UltraWinGrid.UltraGridLayout.Save(Stream stream, PropertyCategories propertyCategories)
at Infragistics.Win.UltraWinGrid.UltraGridLayout.Save(String filename)
at AccessAccounts.Shared.WinForms.Misc.Grid.GridLayout.GridLayoutSerializer.SaveLayoutToFile(String key, String filePath)
at SupplyChain.Forms.InfragisticsUtils.SaveLayout(UltraGrid grid) in C:\Projects\SupplyChain\Forms\InfragisticsUtils.cs:line 2227

However if I put in the following before the save to remove all the editor components from the bands, then I don't get the error when saving.

foreach (var band in grid.DisplayLayout.Bands)
{
  foreach (var column in band.Columns)
  {
    column.EditorComponent = null;
  }
}

Is it possible to explain WHY I'm getting the error and how the above solves it - should I be removing editor components from the grid, since I would have assumed the save method on the GridLayoutSerialize should have checked this.

Many thanks for any help / tips.

Harag

  • 469350
    Suggested Answer
    Offline posted

    Hi Harag,

    You already have an open support case to discuss this issue. In the future, please do not create duplicates by posting the same question you already submitted to support. :)

    One thing that you mentioned here and that your original case doesn't seem to mention is that you are saving the layout in the Dispose method. But you weren't very specific here about the dispose method of what class.

    I'm guessing you are probably using the Dispose method of your form, which seems like a bad place to save a layout. My guess is that you are trying to save the grid layout after one of the controls that you are assigning to the EditorComponent property has already been disposed and that's why you are getting exception - because the grid is trying to save a reference to that component and it's no longer valid. I recommend using the Form_Close or even Form_Closing method to save your layout, instead.