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
75
export to excel returns KeyNotFoundException
posted

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.