This is a migrated thread and some comments may be shown as answers.

Issue with RadGridViewExcelExporter using RadGridview

1 Answer 99 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Patrick Baggett
Top achievements
Rank 2
Patrick Baggett asked on 15 Sep 2011, 05:40 PM
To summarize what I am attempting to do, I am attempting to export data items from a RadListView (databound) to Excel using a RadGridview and RadGridViewExcelExporter.

This is actually a 2-part issue: 
The first issue involves populating with data the RadGridView object that is passed to the RadGridViewExcelExporter (see below).

void Export_to_Excel(String myExcelFile)
{
RadGridView myGridView = new RadGridView();
myGridView.DataSource = myDataSet.joberrors;
RadGridViewExcelExporter exporter = new RadGridViewExcelExporter();
exporter.Export(myGridView, myExcelFile, "Sheet1");
exporter = null;
myGridView = null;
}

myDataSet.joberrors is the datasource of my RadListView and contains 2 rows and 14 columns.  Using the above code, myGridView contains 0 rows and 0 columns even after the datasource is set.

To solve this I used     

    
myGridView.LoadFrom(myDataSet.joberrors.CreateDataReader()); 


now myGridView is successfully populated with data, but the second problem now rears its head...

After exporting the data to Excel using the RadGridViewExcelExporter , the exported worksheet only contains one column - the primary key of myDataSet.joberrors?.

Any ideas what I am doing wrong?  Is there an easier way to do this?

Thanks

1 Answer, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 16 Sep 2011, 07:29 AM
Hello Patrick,

There are a couple of things that you need to consider. First the grid was not meant to be used like this, because of performance considerations it will not bind (normally) until it is loaded (displayed) and even after that, data is being loaded in an asynchronous fashion, so you have that event DataBindingComplete, when you are sure you have data, and after that you can safely export data from the grid.
I would suggest you handle things this way for best results.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
Tags
GridView
Asked by
Patrick Baggett
Top achievements
Rank 2
Answers by
Emanuel Varga
Top achievements
Rank 1
Share this question
or