Csla 3.8 SortedBindingList

Csla 3.8 SortedBindingList

Old forum URL: forums.lhotka.net/forums/t/8430.aspx


Fele posted on Thursday, January 28, 2010

Hi,

I try to modify below property to return sorted list of XX objects.
 private static PropertyInfo<XXListBLB> XXsProperty =   RegisterProperty<XXListBLB>(c => c.XXs);
        public XXListBLB XXs
        {
            get { return GetProperty(XXsProperty); }
        }


This is my version:
 private static PropertyInfo<XXListBLB> XXsProperty =   RegisterProperty<XXListBLB>(c => c.XXs);
        public XXListBLB XXs
        {
            get {
1)                 SortedBindingList<XX> sortedList = new SortedBindingList<XX>( GetProperty(XXsProperty));
2)                 sortedList.ApplySort("OrdNo", ListSortDirection.Ascending);
3)                return (XXListBLB)sortedList;
                 }
        }


Above code generates the following errors:
Line #1 - The type or namespace name 'SortedBindingList" could not be found
Line #2 - "Cannot convert type 'void' to 'Csla.SortedBindingList<XX>'" (if I try to select OrdNo property, it is not in the list)
Line #3 - Cannot convert type SortedBindingList<XX> to XXListBB

What am I doing wrong?


Thx for help
Fele

ajj3085 replied on Thursday, January 28, 2010

A SortedBindingList is a wrapper around a list; it is NOT a subclass though, so you'll never be able to cast it as your XXListBLB class.

Also it doesn't look like any of this code belongs in your business layer at all.  The UI cares about sorting, the SortedBindingList provides a sortable view over your list.

If your list DOES require ordering, it probably needs to be built in as part of the XXListBLB class, and you'll probably have to do things like not allow SetItem.  Only add, and then an ability to ask to move items up or down (if their position is important).

HTH

Andy

JonnyBee replied on Thursday, January 28, 2010

Hi,

Are you using WindowsForms?

The #1 indicates that you are missing a using statement or simply not able to locate the class SortedBindingList in the Csla namespace.

At #3 - You should not try to cast the SortedBindingList into another explicit type. You may use IList<xx> as property type and BusinessListBase, SortedBindingList and FilteredBindingList all implement IList<T>.

xx should be the "child object type " and not the "list type" (I can't read that from your code).

My basic recommendation would be to consider the ortedBindingList to be part of the UI - ie not a part your BO that should (imo) just expose the list and leave sorting to the UI technology chosen. 

Fele replied on Thursday, January 28, 2010

I'm using Silverlight with MVVM. And your are completely right that I should put sort into UI (in my situation my Model class).

Thanks guys.



JonnyBee replied on Friday, January 29, 2010

Hi,

I'd recommend LINQ and LinqBindingList resultset over FilteredBindingList in Silverlight and WPF. SortedBindingList and FilteredBindingList is primarily for WindowsForms DataBinding while LINQ and LinqBindingList is the preferred solution for SL, WPF as it wraps an ObservableCollection rather than BindingList. 

Fele replied on Friday, January 29, 2010

Thanks Jonny.

I forgot to mention that I would like to sort data in 2nd level child list (Parent --> child --> child list). This is why I tried to implement sorting in BO instead UI.

What should I do in this situation?
Implementing sorting in UI will be at least a little messy.


Copyright (c) Marimer LLC