Invalid Cast Exception on Sort Descriptors

4 posts, 0 answers
  1. Tyler
    Tyler avatar
    13 posts
    Member since:
    Jun 2012

    Posted 16 Oct 2012 Link to this post

    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.
  2. Vladislav
    Admin
    Vladislav avatar
    277 posts

    Posted 18 Oct 2012 Link to this post

    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.

  3. Tomáš
    Tomáš avatar
    1 posts
    Member since:
    Dec 2017

    Posted 14 Dec 2017 Link to this post

    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 ...

     

  4. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    686 posts

    Posted 19 Dec 2017 Link to this post

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