Best Practice for Implementing Sorted Views of Lists?

Best Practice for Implementing Sorted Views of Lists?

Old forum URL:

FrazerS posted on Monday, March 01, 2010

On page 74, the book states that with LINQ, the use of SortedBindingList and FilteredBindingList are obsolete. 

What is considered the best approach for providing a sorted version of the list to the UI?   I want to avoid a trip to the data layer.



RockfordLhotka replied on Monday, March 01, 2010

The exception to that statement is Windows Forms. If you are using Windows Forms then you are better off using SortedBindingList and FilteredBindingList. If you bind a SortedBindingList to a datagrid it just works - the sorting request from the control is automatically handled by SBL. But you'll notice that the 2008 book largely ignores Windows Forms - mostly because it is a legacy technology (widely used or not), and partially because the Using CSLA .NET 3.0 ebook has good Windows Forms coverage and I was out of room in the 2008 book.

Arguably Web Forms is an exception as well, since it does have its own sorting/paging model - which is discussed in depth in the CSLA .NET Version 2.1 Handbook ebook. But LINQ is absolutely a valid answer, assuming you are caching your lists in Session and just resorting them on the web server when requested by the user. Most web apps actually just go back to the database though, because Session should generally be avoided.

if you are using WPF, LINQ queries are probably the answer. Though in CSLA 4 the collection base classes now inherit from ObservableCollection<T> and so automatically sort when bound to most datagrid controls. But you still need to use LINQ to sort when bound to something like a ListBox.

If you are using Silverlight, the CSLA collection base classes already inherit from ObservableCollection<T>, so automatic sorting has been there since day 1.

FrazerS replied on Monday, March 01, 2010

Thanks for the clarification.  This helps a great deal.




Copyright (c) Marimer LLC