Hi,
We are using the following code-snippet while trying to save the column widths from the xamDataGrid
Dictionary<string, int> columnWidths = new Dictionary<string, int> ();foreach (Infragistics.Windows.DataPresenter.Field field in _grid.DefaultFieldLayout.Fields){ columnWidth[field.Name] = (int) field.CellWidthResolved;}
but getting the following NullReferenceException
System.NullReferenceException: Object reference not set to an instance of an object.
at Infragistics.Windows.DataPresenter.FieldLayout.a(Boolean A_0, Boolean A_1, c& A_2, c& A_3, Boolean A_4, Boolean A_5)
at Infragistics.Windows.DataPresenter.FieldLayout.b(Boolean A_0, Boolean A_1, c& A_2, c& A_3, Boolean A_4)
at Infragistics.Windows.DataPresenter.FieldLayout.c()
at Infragistics.Windows.DataPresenter.FieldLayout.ax()
at Infragistics.Windows.DataPresenter.VirtualizingDataRecordCellPanel.a(Field A_0, Boolean A_1)
at Infragistics.Windows.DataPresenter.Field.get_CellWidthResolved()
We are calling the above code when from the Unloaded eventHandler of the grid and most of the time it works fine but there are times when the exception reported above is thrown.
From our investigation, we think this exception might be thrown when calling get_CellWidthResolved on the columns which are not currently generated or out of the current view.
Following are the settings we have on the xamDataGrid
_grid.FieldLayoutSettings.AutoGenerateFields = false; _grid.RecordContainerGenerationMode = Infragistics.Windows.Controls.ItemContainerGenerationMode.Recycle;_grid.CellContainerGenerationMode = CellContainerGenerationMode.Recycle;_grid.RecordLoadMode = RecordLoadMode.PreloadRecords;
Do we have any workarounds to acheive the above logic of getting column widths safely without getting the exception, or to get the columns visible in the current view?
Thanks,
Mayank
Hello Mayank,
There is a built-in feature for this in the XamDataGrid - Saving and Loading Customizations. You can call the SaveCustomizations method of the XamDataGrid to save field width and other customizations on the grid.
Please look at this article :
http://community.infragistics.com/wpf/codesamples/save-and-load-customizations-in-the-xamdatagrid.aspx
Regards,
Alex.
Hi Alex,
I don't think the code sample pointed is applicable to 8.1 release of XamDataGrid. Upgrading to 9.1 is not an option for us now.
Any ways to get this working perfectly in 8.1?