Click here to Skip to main content
15,921,577 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have an
C#
ObservableCollection<T>
, it has two properties String Item and String Priority.
i want my LongListSelector to display the items with Priority "High" first then "Low" respectively.
i have tried this but it seem like a stupid idea but i am not that good a programmer yet i am intermediate.
C#
this.List.ItemsSource = this.Items.OrderBy(c => c.Priority == "High");

thank you for your contribution.
Posted
Updated 12-Oct-14 8:16am
v2

1 solution

If you want to sort data in ascending order, use:
C#
this.List.ItemsSource = this.Items.OrderBy(c => c.Priority);

For descending order, use:
C#
this.List.ItemsSource = this.Items.OrderByDescending(c => c.Priority);


That's all ;)

Note: The order of items in a list will not change. You need to implement it.

Please, read this:
how to sort descending order of ObservableCollection?[^]
How to sort an ObservableCollection [^]
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 12-Oct-14 16:08pm    
5ed. Collection is done observable for notifications and for binding.
—SA
Maciej Los 12-Oct-14 16:14pm    
Thank you, Sergey ;)
BillWoodruff 13-Oct-14 6:28am    
+5
Maciej Los 13-Oct-14 6:36am    
Thank you, Bill ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900