RadBusyindicator Freezes when exporting RadGridView to Excel File

Environment

Product Version 2017.3.1018
Product RadBusyIndicator for WPF

Description

RadBusyindicator freezes while RadGridView export is running.

Solution

To minimize this, separate the creating of the document model from the saving of the file. Saving of the file can be executed on a separate thread. Also, use the ExportToWorkbook() method for creating the document model.

private BackgroundWorker backgroundWorker; 
private Stream documentStream; 
 
private void ExportToXlsX(RadGridView gridView) 
{ 
    SaveFileDialog dialog = new SaveFileDialog() 
    { 
        DefaultExt = "xlsx", 
        Filter = String.Format("Workbooks (.{0})|.{0}|All files (.)|.", "xlsx"), 
        FilterIndex = 1 
    }; 
 
    if (dialog.ShowDialog() == true) 
    { 
        var document = gridView.ExportToWorkbook(new GridViewDocumentExportOptions() 
        { 
            ShowColumnFooters = true, 
            ShowColumnHeaders = true, 
            ShowGroupFooters = true 
        });                                 
        this.documentStream = dialog.OpenFile(); 
 
        var backgroundWorker = new BackgroundWorker();       
        backgroundWorker.DoWork += BackgroundWorker_DoWork; 
 
        this.radBusyIndicator.IsBusy = true; 
        backgroundWorker.RunWorkerAsync(document); 
    } 
} 
 
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) 
{ 
    var formatProvider = new XlsxFormatProvider(); 
    formatProvider.Export((Workbook)e.Argument, this.documentStream); 
 
    this.documentStream.Close(); 
 
    App.Current.Dispatcher.BeginInvoke(new Action(() =>  
    { 
        this.radBusyIndicator.IsBusy = false; 
    })); 
} 

See Also

In this article
Not finding the help you need? Improve this article