Hello. I have several grids bound to various different datasources, all of which use the Excel exporting functionality. However, one of the grids encounters an error every time I try to perform an Excel export. For this particular grid, it is bound directly to a typed DataTable in a typed DataSet, without a BindingSource. There is one unbound column in the grid. Below is the exception:
System.ArgumentException: Key already existsParameter name: Key at Infragistics.Shared.KeyedSubObjectsCollectionBase.ValidateKeyDoesNotExist(String key, IKeyedSubObject ignoreObject) at Infragistics.Shared.KeyedSubObjectsCollectionBase.ValidateKey(String key, IKeyedSubObject ignoreObject) at Infragistics.Shared.KeyedSubObjectsCollectionBase.ValidateKey(String key) at Infragistics.Shared.KeyedSubObjectsCollectionBase.InternalAdd(IKeyedSubObject obj) at Infragistics.Win.UltraWinGrid.ColumnsCollection.InternalAdd(UltraGridColumn column) at Infragistics.Win.UltraWinGrid.UltraGridBand.InitColumns(UltraGridBand[] oldBands) at Infragistics.Win.UltraWinGrid.UltraGridBand.InitListManager(BindingManagerBase bindingManager, String dataMember, UltraGridBand[] oldBands) at Infragistics.Win.UltraWinGrid.UltraGridLayout.ListManagerUpdated(BindingManagerBase bindingManager) at Infragistics.Win.UltraWinGrid.UltraGridLayout.ListManagerUpdated() at Infragistics.Win.UltraWinGrid.UltraGrid.Export(IUltraGridExporter exporter) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.Export(UltraGrid grid, Worksheet worksheet, Int32 startRow, Int32 startColumn) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.Export(UltraGrid grid, Workbook workbook) at MyApp.WinForms.Controls.BaseControl.ExportGrid(UltraGrid grid, String title, String initDirectory, Boolean promptToOpen) in D:\Development\MyApp\MyApp.WinForms\Controls\BaseControl.cs:line 882
I am using Infragistics v10.2. Any insight or help you can provide would be greatly appreciated.
Thanks!
Hi,
From the call stack, it appears that the exception occurs when the grid is trying to bind the export layout to the same data source that the real grid is bound to. Which is very odd, since I assume the actual on-screen grid doesn't have any problems like this.
My best guess is that something in your code is trying to re-add the unbound column into the export layout even though it already exists. Are you adding your unbound column in code? If so, what event are you using?
Try setting the Visual Studio IDE to break on all run-time exceptions. I'm guessing that the call stack you have here is not really the problem, but that the real exception is occurring and being caught somewhere else.
Okay, so I set VS to break on all exceptions and it loaded the grid fine, without errors, the only exception it's breaking on is where I call ultraGridExcelExporter.Export(UltraGrid grid, Workbook excelWorkbook).
Good morning, Mike. I appreciate your prompt response!!
The unbound column is added through the designer, but the value of it is set using an InitializeRow event handler. I have tried removing the unbound column completely and removing the InitializeRow event handler subscription, but still the error persists.
Another interesting tidbit -- the error also occurs when trying to print the same grid. The error callstack is similar -- except that it starts in the UltraGrid.Print(UltraGridLayout layout, PrintDocument printDocument, RowPropertyCategories retainRowPropertyCategories) method.
I will try changing the VS settings and see if I can get more details out of this.
Mia