Invalid cast exception on sorting

Hi guys, I'm getting this exception whenever I try to sort a collection of items by any column.
I'm using the DataGrid to display items obtained from nHibernate.
This is a processed collection, after I filter out only required items, so I suppose one of the items has something wrong with it. Does anybody have any idea where I should look?

I've attached a file with the output.

Thanks!



3 Replies

MK Muthukumar Kalyanasundaram Syncfusion Team December 21, 2017 03:51 AM UTC

Hi Catalin, 

Thank you for contacting Syncfusion support. 

We are unable to proceed with the given details, can you please share stack trace of the exception issue. In your update, you have specified it may cause may be wrong items but in general we does not have an issue with this. Could you please share more details such as view model, customization details, XAML or simplified application to reproduce the issue from our end, thereby we could analyze further and update you with the appropriate details at the earliest. 

Regards, 
Muthukumar K 



CP Catalin Pop December 21, 2017 11:42 AM UTC

Hi, 
I managed to find a workaround. I wrapped the domain object in a viewmodel and it works now. Not sure if it's worth pursuing further.
I've attached a stack trace (properly, this time:) 

Attachment: stack_trace_d646bb62.rar


JG Jai Ganesh S Syncfusion Team December 23, 2017 12:47 AM UTC

Hi Catalin, 
Based on the stack trace, you have used two different class types in your underlying collection. Hence the exception occurred while sorting. However, you can resolve this issue by setting the SourceType as underlying collection like below, 
 
this.datagrid.SourceType = typeof(SalesByYear); 
 
 
Regards, 
Jai Ganesh S 


Loader.
Up arrow icon