Hi.
I am trying to do an export to Excel from my grid and am getting the stack dump:
System.Collections.Generic.KeyNotFoundException was unhandled HResult=-2146232969 Message=The given key was not present in the dictionary. Source=mscorlib StackTrace: at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at Infragistics.Win.UltraWinGrid.GridExportCache.GetDocumentBandInfo(UltraGridBand band, PlaceholderType placeHolderType) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.SetCurrentGridObjectSpan(UltraGridExporterHelper exportHelper, UltraGridBand band, UltraGridRow row, PlaceholderType placeHolderType) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.ProcessGridRowInternal(UltraGridExporterHelper exportHelper, UltraGridRow row, ProcessRowParams processRowParams) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExporterHelper.ProcessRow(UltraGridRow row, ProcessRowParams processRowParams) at Infragistics.Win.UltraWinGrid.RowsCollection.InternalTraverseRowsHelper(IUltraGridExporter exporter) at Infragistics.Win.UltraWinGrid.UltraGrid.Export(IUltraGridExporter exporter) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.ExportHelper(UltraGrid grid, Worksheet worksheet, Int32 startRow, Int32 startColumn, Boolean asynch) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.Export(UltraGrid grid, Worksheet worksheet, Int32 startRow, Int32 startColumn) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.Export(UltraGrid grid, WorkbookFormat workbookFormat) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.Export(UltraGrid grid, String fileName, WorkbookFormat workbookFormat) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.Export(UltraGrid grid, String fileName) at ComputersUnlimited.Windows.Ultra.UltraGridExcelExporter.DoExport()
My exporter is defined like this:var exporter = new Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter();The call that causes the error is this:exporter.Export( Grid, FileName );
Our grid has 2 bands on it and the second band has 1 row in it.Each row (Grid.Rows) has a single ChildBand (Grid.Rows[0].ChildBands.Count = 1) and each ChildBand also has 1 row (Grid.Rows[0].ChildBands[0].Rows.Count = 1) with no ChildBands (Grid.Rows[0].ChildBands[0].Rows[0].ChildBands.Count = null).
I know that if I hide the child band then the export works and also does not export the child band.
What I would like to know is what the message: 'KeyNotFoundException: The given key was not present in the dictionary.' means, what is it looking for specifically and what settings/properties/data might be causing this problem to occur. Is there some information on the band that I need and am missing, since this seems to fail in GetDocumentBandInfo.
Thank you for your time and help in this matter. Anything could be useful.
Hi,
What version of the tools are you using? There is a similar bug that we've already fixed (144342) for versions 12.2 and later. The stack trace is similar but not an exact match:
at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at Infragistics.Win.UltraWinGrid.GridExportCache.GetDocumentBandInfo(UltraGridBand band, PlaceholderType placeHolderType) at Infragistics.Win.UltraWinGrid.GridExportCache.HasVisibleGroupsOrColumnHeadersOnTop(UltraGridBand band) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.ProcessGridRowInternal(UltraGridExporterHelper exportHelper, UltraGridRow row, ProcessRowParams processRowParams) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExporterHelper.ProcessRow(UltraGridRow row, ProcessRowParams processRowParams) at Infragistics.Win.UltraWinGrid.RowsCollection.InternalTraverseRowsHelper(IUltraGridExporter exporter) at Infragistics.Win.UltraWinGrid.RowsCollection.InternalTraverseRowsHelper(IUltraGridExporter exporter) at Infragistics.Win.UltraWinGrid.UltraGrid.Export(IUltraGridExporter exporter) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.ExportHelper(UltraGrid grid, Worksheet worksheet, Int32 startRow, Int32 startColumn, Boolean asynch) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.Export(UltraGrid grid, WorkbookFormat workbookFormat) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.Export(UltraGrid grid, String filename)
Providing a sample I can say for sure what version you were using and if this bug fix also addresses what you are encountering.
Also another older bug (126441, also addressed in 12.2 and later) had a similar exception when exporting the grid and has the following title, "A "KeyNotFoundException" is thrown when exporting the grid with hidden columns of the first band, and header placement of the second band is set to "FixedOnTop"."
Sorry about that, I knew I forgot at least one thing. We are using 15.1.
I'll look though the information you gave me and see if it solves the problem.
I think we have narrowed it down to a combination of lines that include (UltraGridBand)band.RowLayoutStyle= RowLayoutStyle.ColumnLayout; and header visibility.
We also had a similar problem back in your 7.1 tools with the now obsolete line (UltraGridBand)band.UseRowLayout = true; and the same combination of lines of code.
I was working with Doug on this issue. Attached is a zip file that contains some code that seems to duplicate the problem we were encountering.
Hi Jared,
Thanks for the reproduction sample, it was very easy to track down with this information. This was fixed in build 15.1.20151.2214 and the latest Service Release for 15.1 is 15.1.20151.2230 and includes the fix. Go to your account and download the latest 15.1 SR and test your reproduction sample with that SR. My initial search failed to find this bug because the KeyNotFoundException was buried in another field of the bug work item... for future reference the bug number is 212312.
I was able to test the SR and found that it did indeed appear to fix the problem. Thank you for your help in this matter and for the quick response. That is a great feature of Infragistics.
Hi Doug,
Supplying that reproduction sample made it really easy to track down. Thanks again for sending that along. Sorry I couldn't find the bug sooner that matched the stack trace but better to be sure with a reproduction.
Post again if something else comes up!