AUTHOR: Hristo Merdjanov
DATE MODIFIED : December 05, 2016
DATE POSTED: June 21, 2016
RadGridView provides async exporting capabilities out of the box. However, due to the background threads we are using and the target framework against which our assemblies are built (.NET 4.0) we are not exporting the visual settings with the existing async API.
Luckily in .NET 4.5 Microsoft introduced the async methods accompanied by the await statement. Essentially this allows heavy work to be done without freezing the UI. By definition the new async methods do not run on a separate thread so we should not worry about cross thread exceptions. The following MSDN article provides detailed information: Asynchronous Programming with Async and Await.
.NET 4.5 and UI for WinForms Q2 2015 (version 2015.2.623) or later.
We are going to use the newly introduced async functionality and export RadGridView asynchronously preserving all of its visual settings.
The picture below compares the Excel output with the grid in our application
We will start the exporting process in the Click event handler of a RadButton. Since only async methods can be awaited, we need to mark our event handler as async. The actual export job will be also separated in its own async method. If you prefer you can instead use a lambda expression.
private async void radButton1_Click(object sender, EventArgs e)
private async Task ExportGridVisuallyAsync()
Action job = new Action(this.ExportData);
Task task = new Task(job);
private void ExportData()
GridViewSpreadExport spreadExporter = new GridViewSpreadExport(this.radGridView1);
spreadExporter.ExportVisualSettings = true;
SpreadExportRenderer exportRenderer = new SpreadExportRenderer();
sender, EventArgs e)
async Task ExportGridVisuallyAsync()
Action job =
Task task =
GridViewSpreadExport spreadExporter =
SpreadExportRenderer exportRenderer =
Private Async Sub RadButton1_Click(sender As Object, e As EventArgs) Handles radButton1.Click
Private Async Function ExportGridVisuallyAsync() As Task
Dim job As New Action(AddressOf Me.ExportData)
Dim task As New Task(job)
Private Sub ExportData()
Dim spreadExporter As New GridViewSpreadExport(Me.radGridView1)
spreadExporter.ExportVisualSettings = True
Dim exportRenderer As New SpreadExportRenderer()
The GridViewSpreadExport object defines a CellFormatting event and if needed you can subscribe to it and perform custom styling only to the Excel cells: GridViewSpreadExport | Events.
Copyright © 2016, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.