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
Hi Fasiha,
I'm not sure I understand your question. The code you have here is always setting SkipRow and SkipDescendants to false, so this will essentially do nothing.
Hi,
I'm used Initialize Row event to export child bands in excel. I'm getting the output. But my problem is that it dosen't exporting Column header of child bands. Am i missing any thing?
//To export child band in excel
private static void excelExporter_InitializeRow(object sender, ExcelExportInitializeRowEventArgs e) { UltraGrid grid = e.Row.Band.Layout.Grid as UltraGrid; UltraGridRow realGridRow = grid.GetRowFromPrintRow(e.Row); e.Row.Band.Header.Activated = true; if (realGridRow.Band.Index == 1 && realGridRow.Selected == false) { e.SkipRow = false; e.SkipDescendants = false; } else if (realGridRow.Band.Index == 2 && realGridRow.Selected == false) { e.SkipRow = false; e.SkipDescendants = false; } }
Thanks & Regards,
Fasiha
Could you post a sample which reproduces the unwanted behavior?
-Justin
Hi
I am Dhanraj.
I implement the above code successfully selected rows exported.
but didn't show the header name of particular child.
Pls help me..
After playing with this a bit more, I noticed that I was getting extra group by rows in my export. I solved this by using the following code. It seems to cover all of the scenarios that my application runs into. Initially I was worried about performance issues from iterating child rows, however; as long as foundSelectedRows == false is the common scenario (as it is in my app), the performance hit shouldn't be too large. Thanks for the help.
private void ultraGridExcelExporter1_InitializeRow(object sender, ExcelExportInitializeRowEventArgs e) { bool foundSelectedRows = false; UltraGrid grid = e.Row.Band.Layout.Grid as UltraGrid; UltraGridRow realGridRow = grid.GetRowFromPrintRow(e.Row); if (realGridRow.IsGroupByRow) { foreach (UltraGridChildBand band in realGridRow.ChildBands) { foreach(UltraGridRow row in band.Rows) { if (row.Selected) { foundSelectedRows = true; break; } } } if (foundSelectedRows == false) { e.SkipRow = true; e.SkipDescendants = true; } } else if (realGridRow.Band.Index == 0 && realGridRow.Selected == false) { e.SkipRow = true; e.SkipDescendants = true; } }