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

Invalid Cast Exception on Sort Descriptors

3 Answers 58 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Tyler
Top achievements
Rank 1
Tyler asked on 16 Oct 2012, 03:38 PM
I am working on an application and using the Persistence Framework to save the settings of the Gridview I am using. I have the code from your demos in place and everything seems to work except I continue to get an InvalidCastException on the ColumnSortDescriptors when I save the seetings only in certain situations. If I group one column then save the settings the application will throw the exception, however, if I only change the sort of one column and save then everything saves perfectly and the exception is not thrown on the same line of code. Any help would be greatly appreciated. I will attach a picture of the exception to the post.

3 Answers, 1 is accepted

Sort by
0
Vladislav
Telerik team
answered on 18 Oct 2012, 01:17 PM
Hi Tyler,

Unfortunately we wasn't able to reproduce the described issue on our side.
I made a simple project based on the example in our Demo and it seems to work properly in the scenario described.
Could you please try this project and let us know if you get this exception with it?

If you encounter this exception only in your project, it will be best if you can send it to us, in order to investigate the problem. It will also be helpful for us to know the exact version of the controls you are using.

Thank you in advance.

Kind regards,
Vladislav
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tomáš
Top achievements
Rank 1
answered on 14 Dec 2017, 02:03 PM

It happens when you have some SortDescriptor on your grid like this

---------------------------------------------------------------------------------------------------------------------------------------------

<telerik:RadGridView.SortDescriptors>
                            <telerik:SortDescriptor Member="PosterPosition.PosterPage.OrderNumber"/>
                            <telerik:SortDescriptor Member="PosterPosition.OrderNumber"/>
                        </telerik:RadGridView.SortDescriptors>
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding PosterPosition.PosterPage.OrderNumber}"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding PosterPosition.OrderNumber}"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding ...

---------------------------------------------------------------------------------------------------------------------------------------------

replace them with ColumnSortDescriptors:

---------------------------------------------------------------------------------------------------------------------------------------------

<telerik:RadGridView.SortDescriptors>
                            <telerik:ColumnSortDescriptor Column="{Binding Columns[\PosterPageOrderNumber], ElementName=posterHeaderRadGrid}" SortDirection="Ascending"/>
                            <telerik:ColumnSortDescriptor Column="{Binding Columns[\OrderNumber], ElementName=posterHeaderRadGrid}" SortDirection="Ascending"/>
                        </telerik:RadGridView.SortDescriptors>
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding PosterPosition.PosterPage.OrderNumber}" UniqueName="PosterPageOrderNumber" Name="PosterPageOrderNumber"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding PosterPosition.OrderNumber}" UniqueName="OrderNumber" Name="OrderNumber"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding ...

 

0
Vladimir Stoyanov
Telerik team
answered on 19 Dec 2017, 01:33 PM
Hi Tyler,

Thank you for sharing your solution with the community.

The GridViewCustomPropertyProvider class in the GridViewSerialization example in our demos expects to persist ColumnSortDescriptor instead of SortDescriptor. You are correct that this is the reason for the InvalidCastException in the first post. 

Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
PersistenceFramework
Asked by
Tyler
Top achievements
Rank 1
Answers by
Vladislav
Telerik team
Tomáš
Top achievements
Rank 1
Vladimir Stoyanov
Telerik team
Share this question
or