Issue with RadGridViewExcelExporter using RadGridview

2 posts, 0 answers
  1. Patrick Baggett
    Patrick Baggett avatar
    9 posts
    Member since:
    Aug 2012

    Posted 15 Sep 2011 Link to this post

    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     


    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?

  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 16 Sep 2011 Link to this post

    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
Back to Top