We are in the process of adding export to XLS / PDF and printing support to our grids using the UltraGridPrintDocument, UltraPrintPreviewDialog, UltraGridDocumentExporter and the UltraGridExcelExporter.
The core printing and export functionality is all working nicely except for one issue. We have a number of columns showing in our UltraGrid that while they need to be displayed on screen should be excluded from any printout or export. Is there an easy way to achieve this please?
If it makes a difference the grid uses a mix of bound and unbound columns.
Regards,
Simon Geering.
You can use the exporter BeginExport event to hide any column you want.
Thanks for your reply Amiram, I've put together the following event handlers for this but am having no joy:
Private Shared Sub Exporter_BeginExport(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.DocumentExport.BeginExportEventArgs) Handles mobjUltraGridDocumentExporter.BeginExport Hide_Columns(e.Layout) End Sub Private Shared Sub mobjUltraGridExcelExporter_BeginExport(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.ExcelExport.BeginExportEventArgs) Handles mobjUltraGridExcelExporter.BeginExport Hide_Columns(e.Layout) End Sub
Which then call:
Private Shared Sub Hide_Columns(ByRef objDisplay_Layout As Infragistics.Win.UltraWinGrid.UltraGridLayout) For Each objBand In objDisplay_Layout.Bands For Each strFieldName In mstrHidden_Fields If objBand.Columns.Exists(strFieldName) Then objBand.Columns(strFieldName).Hidden = True End If Next Next End Sub
I must be missing something because the Hidden property seems to have no impact on if the column is visible in the export. In this test case i use CSV as the target export format since it is easier to verify the results for hiding columns at the end of the grid than in XLS format.
Anyone any ideas?
Is the instance of the grid you get in the event args the same as the underlying grid or is it a clone in the same way I understand that printing makes a clone of your grid for printing only. If so I can always get round this by removing the columns but I would of thought this should not be needed!
Any help gratefully appreciated
Hi Mike,
As to my original issue further testing lead to the conclusion that only the CSV export was having issues and it turned out that was going off into another of our functions for pre-processing which didn't take into account the hidden columns! So user error on our part, not a bug or even anything to do with the Infragistics part of the code in the end :-)
As an aside my thanks for confirming that the Layout that is passed into these events is a clone of the grid's DisplayLayout as this has just helped out a colleague reduce the amount of code he needed to use in his work with similar export code on another of our products.
Amiram,
Thanks for getting me on the right track with the correct event handlers to start with, all is working now.
Simon G
Normal 0 false false false EN-GB X-NONE X-NONE MicrosoftInternetExplorer4
The Layout that is passed into these events is a clone of the grid's DisplayLayout and modifying that layout will affect the exported/printed results.
The only reason I can think of why this would not work is that the field names are not being found and so the code which hides the columns is never getting hit.