Hello, I have a ultragrid, and this is grouped by a column, and when i select one group, y need export to excel only rows that are selected.
I want to export both the parent and the children, but only for rows where the parent row is selected.
How i can this?
Tanks
tanks its work fine
Hi,
The row passed in to the exported is not the same object that is used by the grid, it's a clone. So no exported rows will ever be selected. What you need to do is get the row from the grid on the screen that corresponds to the export row.
Using the index (as Trausti does in his sample code) is okay most of the time, but it's not 100% reliable, so I would not use the index. Instead, you should use the GetRowFromPrintRow method on the grid to get the real row.
Once you have the on-screen grid row, you can simply check it's Selected property or the Selected property of it's parent rows and then decide whether to export it or not.
Assuming you want to export every row that is either selected or has an ancestor that is selected, you would do this:
private void ultraGridExcelExporter1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.ExcelExportInitializeRowEventArgs e) { UltraGrid grid = (UltraGrid)e.Row.Band.Layout.Grid; UltraGridRow onScreenRow = grid.GetRowFromPrintRow(e.Row); bool selected = this.IsRowOrAncestorSelected(onScreenRow); if (false == selected) e.Row.Hidden = true; } private bool IsRowOrAncestorSelected(UltraGridRow row) { UltraGridRow ancestor = row; while (ancestor != null) { if (ancestor.Selected) return true; ancestor = ancestor.ParentRow; } return false; }
Tanks for your answer, but this only works if don't have any group.
but i need export the selected parent row, and all its childrens.
I expected this to work:
Private Sub UltraGridExcelExporter1_RowExporting(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.ExcelExport.RowExportingEventArgs) Handles UltraGridExcelExporter1.RowExporting
If Not e.GridRow.Selected Then
e.Cancel = True
End If
End Sub
But it did not. For some reason e.GridRow.Selected was always false so all row where skipped.
Changing it to this and it works (but you may have to change the code to fit your situation):
If Not UltraGrid1.Rows(e.GridRow.Index).Selected Then
Trausti