RadListView and PropertySortDescriptor

1 Answer 57 Views
ListView (obsolete)
lukerobi
Top achievements
Rank 1
Iron
lukerobi asked on 23 Jul 2024, 09:38 PM
Using the example from: https://docs.telerik.com/devtools/maui/controls/listview/sorting#propertysortdescriptor

I am having issues adding a PropertySortDescriptor to ObservableCollection<SortDescriptorBase> without getting a type error.



I have tried playing around with things and I just can't seem to get it working based on the reference I have.  Any ideas?  I have tried using listView.SortDescriptors.Add without luck... I have tried binding it to a collection per the docks to no avail, and I've tried to move the types around to see if I can get a better result... nothing seems to work?


        _radListViewModel.SortDescriptors.Add(new PropertySortDescriptor() { PropertyName = "PickupNumber", SortOrder = SortOrder.Ascending }); // Conversion Error
        listView.SortDescriptors.Add(new PropertySortDescriptor() { PropertyName = "SchedArriveEarly", SortOrder = SortOrder.Ascending }); // Conversion Error
        listView.SortDescriptors.Add(new Telerik.Maui.Controls.Compatibility.DataControls.ListView.SortDescriptorBase() { PropertyName = "PickupNumber", SortOrder = SortOrder.Ascending }); // Error, its a type and cannot be used to create an instance


1 Answer, 1 is accepted

Sort by
1
Accepted
Didi
Telerik team
answered on 24 Jul 2024, 05:36 AM

Hello Luke,

The sort descriptor in the example here is defined as follow:

<telerik:RadListView x:Name="listView" 
                     ItemsSource="{Binding Items}">
    <telerik:RadListView.BindingContext>
        <local:ViewModel/>
    </telerik:RadListView.BindingContext>
    <telerik:RadListView.SortDescriptors>
        <telerik:ListViewPropertySortDescriptor PropertyName="Age" 
                                                SortOrder="Ascending" />
    </telerik:RadListView.SortDescriptors>

It is ListViewPropertySortDescriptor not SortDescriptor. Please use the correct type.

Regarding to the bindable sort descriptor example -> The example works as expected. Here is the example's source code: https://github.com/telerik/maui-samples/tree/main/Samples/SdkBrowser/Examples/ListViewControl/SortingCategory/BindablePropertySortDescriptorExample 

Regards,
Didi
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

lukerobi
Top achievements
Rank 1
Iron
commented on 24 Jul 2024, 12:52 PM

what about doing it programatically? without xml? 
Didi
Telerik team
commented on 24 Jul 2024, 01:11 PM

here is an example: 

RadListView listview = new RadListView();
listview.SortDescriptors.Add(new Telerik.Maui.Controls.Compatibility.DataControls.ListView.ListViewPropertySortDescriptor { PropertyName = "MyProperty" });

lukerobi
Top achievements
Rank 1
Iron
commented on 08 Aug 2024, 02:20 PM

Thanks, this is what I was having difficulty locating.
Tags
ListView (obsolete)
Asked by
lukerobi
Top achievements
Rank 1
Iron
Answers by
Didi
Telerik team
Share this question
or