Hello,
we are using a UltraGridExcelExporter component to export a grid to an excel worksheet. It works quite fine, but if we need to export a large number of rows it takes its time. Now we want to implement a simple logic to export only selected rows of the grid, so we used the rowexporting event. This should also work fine to skip the non selected rows of the grid.
But what should we do, if the user wants to cancel the complete exporting? I suppose, we could use the EndExportEventArgs.Cancelled property to know when it was cancelled, but how do i set this property?
Greetings
You can cancel the exporting during the InitializeRow event of the UltraGridExcelExporter. There are properties on the event args to allow you to skip child rows, skip individual rows, and cancel. So this is probably a better place to hide the non-selected rows, too.
Hello Mike,
your answer helped me a lot ;-) thanks.
But i need a quick suggestion on how to find out which parent rows are to be exported, when a child row of a parent row is selected. This is because for every parent row and every child row the InitializeRow event is fired.
If a ParentRow is selected i want to export all Childrows
if a single childrow is selected i want to export the parentrow and all childrows of that parent.
We counted the number of selected parentrows and for each of these parentrows we counted the number of childrows. that gets us a number at appr. 1000
but if InitializeRow is fired none of the childrows get exported because their parentrow isnt selected either (even if we selected all parent rows in the grid).
It sounds like your InitializeRow event handler is going to have to check the parent and child rows of each row that gets initialized.
So when InitializeRow fires for a parent row and that row is not selected, you will need to check it's child rows (e.Row.ChildBands["key"].Rows) and loop through them to see if any of them are selected.
And for the child rows, you will have to do the same thing and examine the parent row.
Another quick reply :-)
Now I think, i have the solution
e.Row.Selected applies to the Excel Rows (target Rows), because when i set this to true, all of my Excel Rows become selected (same color as in my UltraGrid).
So tihs could be a BUG ???
Hi Wolfgang,
Sorry, there's one small catch to this which I forgot to mention. The e.Row you get inside this event is not an Excel row, but it's not the grid row that you see on-screen, either. It's essentially a clone of the grid row and it doesn't copy over the selected state from the on-screen row.
So the first thing you need to do here is get the real on-screen grid row from the cloned row. Here's how you do it:
UltraGrid grid = (UltraGrid)e.Row.Band.Layout.Grid;UltraGridRow realGridRow = grid.GetRowFromPrintRow(e.Row);
Now you can check the Selected state on the realGridRow. When you want to check the parent or child rows, use realGridRow instead of e.Row so you are working with the on-screen rows instead of the export rows.