In my application, I have a grid with a maximum of two bands. When the user makes a context menu selection on band[0] to export to excel, all selected rows in band[0] will be exported along with any child rows in band[1]. When I do this, I get extra ColumnHeader rows in my excel. Is there a way to only get the ColumnHeader rows for the for the rows that I am exporting?
Here is the code I am using to handle the selected row export:
private void ultraGridExcelExporter1_RowExporting(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.RowExportingEventArgs e) { UltraGrid grid = e.GridRow.Band.Layout.Grid as UltraGrid; UltraGridRow realGridRow = grid.GetRowFromPrintRow(e.GridRow); if (realGridRow.Band.Index == 0 && realGridRow.Selected == false) { e.Cancel = true; } else if (realGridRow.Band.Index == 1 && realGridRow.ParentRow.Selected == false) { e.Cancel = true; } }
Any help is appreciated.
Thanks,
Justin
That worked perfectly for my needs. Thanks!!!
Hi Justin,
Instead of using the RowExporting event, use the InitializeRow event on the UltraGridExcelExporter, instead. Note that this is an event on the Export, I am not referring to the InitializeRow event on the grid itself.
Then you can do essentially the same code as above, excelt instead of setting e.Cancel to true, you set e.SkipRow to true to skip the row.
After that, you can check the child rows and see if none of them are selected. To get the child rows, you would do something like this:
e.Row.ChildBands[0].Rows
Loop through these rows and get each one's corresponding "real" grid row using GetRowFromPrintRow and see if it is selected.
If NONE of the child rows are selected, you can set e.SkipDescendants to true to cancel the export of all of the child rows - this should also account for the header.
An alternative method would be to use the HeaderExporting event and use the GridRow there to get the rows collection and do the same thing - loop through all the rows in the collection and see if any are selected and if not, cancel the header export.
The first method is better, though, because it will also account for summaries and anything else that might be exported along with the rows.