Hi,
I need to apply a formula into the selected WorksheetRegion. I'm using the following code to achieve this:
var selectionRange = _grid.ActiveSelection.CellRanges.First(); formula.ApplyTo(new WorksheetRegion(_grid.ActiveWorksheet, selectionRange.FirstRow, selectionRange.FirstColumn, selectionRange.LastRow, selectionRange.LastColumn));
It works well, except when I try to copy and paste the resulting data. A couple of copy/pastes causes the following null reference exception:
System.NullReferenceException: Object reference not set to an instance of an object. at Infragistics.Documents.Excel.Serialization.BIFF8.Biff8RecordStream.WriteRefU(WorksheetRegion region) at Infragistics.Documents.Excel.Serialization.BIFF8.BiffRecords.SHRFMLARecord.Save(WorkbookSaveManagerExcel2003 saveManager) at Infragistics.Documents.Excel.Serialization.WorkbookSaveManagerExcel2003.WriteRecord(BIFF8RecordType type) at Infragistics.Documents.Excel.Serialization.BIFF8.BiffRecords.FORMULARecord.SaveCellValue(WorkbookSaveManagerExcel2003 saveManager, MemoryStream initialData) at Infragistics.Documents.Excel.Serialization.WorkbookSaveManagerExcel2003.WriteRecord(BIFF8RecordType type) at Infragistics.Documents.Excel.Serialization.WorkbookSaveManagerExcel2003.WriteCellRecord() at Infragistics.Documents.Excel.Serialization.WorkbookSaveManagerExcel2003.<>c__DisplayClass15.<>c__DisplayClass17.<WriteWorksheetRowBlock>b__12(CellDataContext cellDataContext) at Infragistics.Documents.Core.Async.ForEachSliceHelper`1.ExecuteNext() at Infragistics.Documents.Core.Async.Try(Func`1 try, Action finally) at Infragistics.Documents.Excel.Serialization.WorkbookSaveManagerExcel2003.<>c__DisplayClass15.<WriteWorksheetRowBlock>b__11(WorksheetRow row) at Infragistics.Documents.Core.Async.ForEachHelper`1.ExecuteNext() at Infragistics.Documents.Core.WorkItem.WorkItemAsync.ExecuteCore(WorkItemScheduler scheduler) at Infragistics.Documents.Core.WorkItem.Execute(WorkItemScheduler scheduler)--- End of stack trace from previous location where exception was thrown --- at TryThrowExceptionDispatchInfo(Object ) at Infragistics.Documents.Core.WorkItem.ExceptionInfo.Rethrow() at Infragistics.Documents.Core.WorkItemExtensions.GetResult[TResult](WorkItem`1 this) at Infragistics.Documents.Excel.Serialization.WorkbookSaveManagerExcel2003.<>c__DisplayClass21.<WriteWorksheetRowBlocks>b__1f(WorkItem`1 t) at Infragistics.Documents.Core.WorkItem.WorkItemSync.ExecuteCore(WorkItemScheduler scheduler) at Infragistics.Documents.Core.WorkItem.Execute(WorkItemScheduler scheduler)--- End of stack trace from previous location where exception was thrown --- at TryThrowExceptionDispatchInfo(Object ) at Infragistics.Documents.Core.WorkItem.ExceptionInfo.Rethrow() at Infragistics.Documents.Core.WorkItemExtensions.GetResult[TResult](WorkItem`1 this) at Infragistics.Documents.Excel.Serialization.WorkbookSaveManagerExcel2003.<>c__DisplayClassc.<SaveWorksheet>b__b(WorkItem`1 t) at Infragistics.Documents.Core.WorkItem.WorkItemSync.ExecuteCore(WorkItemScheduler scheduler) at Infragistics.Documents.Core.WorkItem.Execute(WorkItemScheduler scheduler)--- End of stack trace from previous location where exception was thrown --- at TryThrowExceptionDispatchInfo(Object ) at Infragistics.Documents.Core.WorkItem.ExceptionInfo.Rethrow() at Infragistics.Documents.Core.WorkItemExtensions.<ExecuteWithDefaultScheduler>b__0(WorkItem t) at Infragistics.Documents.Core.WorkItem.WorkItemSync.ExecuteCore(WorkItemScheduler scheduler) at Infragistics.Documents.Core.WorkItem.Execute(WorkItemScheduler scheduler)--- End of stack trace from previous location where exception was thrown --- at TryThrowExceptionDispatchInfo(Object ) at Infragistics.Documents.Core.WorkItem.ExceptionInfo.Rethrow() at Infragistics.Documents.Core.WorkItem.RunNextWorkItem(WorkItemScheduler scheduler) at Infragistics.Documents.Core.WorkItem.Execute(WorkItemScheduler scheduler) at Infragistics.Documents.Core.WorkItemScheduler.SynchronousImpl.Execute(WorkItem workItem) at Infragistics.Documents.Excel.Workbook.Save(Stream stream, WorkbookSaveOptions saveOptions) at Infragistics.Controls.Grids.Core.IGExcelSerializationProvider.Save(WorkbookDataObjectSaveContext context) at Infragistics.Controls.Grids.Core.WorkbookDataObjectManager.CreateDataObject(Boolean isDragDrop) at Infragistics.Controls.Grids.Core.WorkbookDataObjectManager.CopyToClipboard() at Infragistics.Controls.Grids.Core.Spreadsheet.ExecuteCommand(SpreadsheetCommandType command, Object commandParameter, Object sourceElement, Int64 currentState) at Infragistics.Controls.Grids.Core.Spreadsheet.ProcessKeyDown(Key key, ModifierKeys modifierKeys) at Infragistics.Controls.Grids.XamSpreadsheet.ProcessKeyDown(KeyEventArgs e) at Infragistics.Controls.Grids.Primitives.SpreadsheetCellEditor.OnKeyDown(KeyEventArgs e) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled) at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers) at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg) at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled) at System.Windows.Interop.ThreadMessageEventHandler.Invoke(MSG& msg, Boolean& handled) at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at Desktop.App.Main()
Hello Tg,
I have been looking into your issue but unfortunately I am not able to reproduce it. Can you please provide me with information what version of our components you are using and review the sample that I have created for you and see whether it works on your environment or try to modify in such a way that I can reproduce it also?
The steps I tried are:1) Select some region (e.g. D1:F1)2) Press the button "ApplyFormula"3) Copy the selected region4) Paste the date somewhere else
And didn't notice nothing strange and NRE was not thrown.
I am looking forward to hearing from you.
I am using Infragistics WPF 15.2. I tried your sample, and it also fails (this time when pasting). It's still probably the same problem though.
The steps to reproduce this:
1) Select some region
2) Press the button "ApplyFormula"
3) Copy some part of the resulting data
4) Paste it
5) Copy some other part of the data
6) Paste it