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
185
NullReferenceExcpetion on get_CellWidthResolved
posted

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

 

Parents
No Data
Reply Children