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

[Solved] Excel export - System.InvalidCastException

3 Answers 140 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
KodeKreachor
Top achievements
Rank 1
KodeKreachor asked on 19 Feb 2010, 08:05 PM
We are getting the following exception when trying to export any RadGridView's to excel:
System.InvalidCastException
   at Telerik.Windows.Controls.ExportExtensions.GetRowValues(GridViewDataControl source, IEnumerable items, StringBuilder& builder, ExportFormat format)
   at Telerik.Windows.Controls.ExportExtensions.ToExcelML(GridViewDataControl source, IEnumerable items, Boolean includeHeader)
   at Telerik.Windows.Controls.ExportExtensions.ToExcelML(GridViewDataControl source, Boolean includeHeader)

Does anyone have any suggestions as to what could be causing this?

Thanks,
Eric

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 22 Feb 2010, 07:07 AM
Hello Eric,

Can you post more info about the grid version, your scenario and how to reproduce this?

Sincerely yours,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
KodeKreachor
Top achievements
Rank 1
answered on 22 Feb 2010, 02:59 PM

Hi Vlad,
Currently we're trying out Telerik's trial version of the Silverlight gridview (file version: 2009.3.1314.1030).
We are implementing the MVVM pattern. We have a view model property declared on our view.

Public partial class EquipmentDetail : UserControl 
{
   public ViewModel ViewModel  
   {
      get  
      {
            return _vm; 
  
   }
      set  
      {         
            _vm =
value
            this.DataContext = _vm; 
      }
   }

   private ViewModel _vm;
}


Our view model contains an ObservableCollection of a second view model:
public ObservableCollection<Part_ViewModel> Parts;

On our Parts view model we have a number of public string properties and two DateTime properties.
The export to excel works when we remove the DateTime properties. But when we add them back to the Parts view model, they bind successfully to the gridview but the aforementioned exception is thrown when trying to export to Excel.

Thanks,
Eric

0
Vlad
Telerik team
answered on 24 Feb 2010, 07:44 AM
Hi Eric,

I've just tried this using our latest service pack however everything worked as expected on my end. You can check the attached project for reference.

Regards,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
KodeKreachor
Top achievements
Rank 1
Answers by
Vlad
Telerik team
KodeKreachor
Top achievements
Rank 1
Share this question
or