Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
350
How to Expand GroupBy group in run-time to reflect in the Excel export?
posted

Hi,

I'm doing a report in excel, before i export the grid i group it in GroupBy mode by a specific column, in run time, but when i open the excel file the rows are collapsed. I did it in another report where the user manually drag the column and groupBy the grid and after he exported it the rows were expanded. I need to do the same but in run-time without drag and drop to grouBy area. So, i need to do some refresh to the grid before the export or something else?. i ll put some code:

At Init:

this.ugPrincipal.DisplayLayout.Override.GroupByRowInitialExpansionState = GroupByRowInitialExpansionState.Expanded;

At Export Code:

                ugPrincipal.DisplayLayout.Bands[0].SortedColumns.Clear();               
                ugPrincipal.DisplayLayout.Bands[0].SortedColumns.Add("Batch", false, true);
                ugPrincipal.DisplayLayout.Bands[0].SortedColumns.Add("SubPos", false);
               
                excelExporter.Export(ugPrincipal,
                                                     "SheetName",
                                                      1,
                                                      0);

                ugPrincipal.DisplayLayout.Bands[0].SortedColumns.Clear();
                ugPrincipal.DisplayLayout.Bands[0].SortedColumns.Add("Batch", false);
                ugPrincipal.DisplayLayout.Bands[0].SortedColumns.Add("SubPos", false);

All this proc is done in run-time.

 

 

Help!!!!!

 

Best Regards! :D

Parents
No Data
Reply
  • 469350
    Suggested Answer
    Offline posted

    Hi,

    What you appear to be doing here is modifying the layout of the on-screen grid just so that it will be grouped when you export, then fixing up the layout. This is really not a good way to do it. There is a much easier way.

    When the grid is exported, the grid creates a clone of it's own DisplayLayout. You can modify this cloned layout without affecting the on-screen grid. So what you should do is the BeginExport event of the UltraGridExcelExporter. This event passes you the layout. So you could save yourself some code and avoid affecting the on-screen grid by doing this:


            private void ultraGridExcelExporter1_BeginExport(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.BeginExportEventArgs e)
            {

                e.Layout.ViewStyleBand = ViewStyleBand.OutlookGroupBy;
                e.Layout.Bands[0].SortedColumns.Clear();
                e.Layout.Bands[0].SortedColumns.Add("Batch", false, true);
                e.Layout.Bands[0].SortedColumns.Add("SubPos", false);

            }

    To get all of the rows to be expanded initially, you could do this:


            private void ultraGridExcelExporter1_EndExport(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.EndExportEventArgs e)
            {
                foreach (WorksheetRow row in e.CurrentWorksheet.Rows)
                {
                    row.Hidden = false;
                }
            }

     

Children
No Data