CSLA .NET

From Rockford Lhotka's Expert C# 2008 and VB 2008 Business Objects books

Csla 3.8 SortedBindingList

rated by 0 users
This post has 5 Replies | 0 Followers

Top 500 Contributor
Posts 25
Fele Posted: Thu, Jan 28 2010 3:01 PM
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

Top 10 Contributor
Posts 3,716
Andy replied on Thu, Jan 28 2010 3:48 PM

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

Top 25 Contributor
Posts 312
JonnyBee replied on Thu, Jan 28 2010 3:58 PM
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. 
Jonny Bekkum, Norway CslaContrib Coordinator
Top 500 Contributor
Posts 25
Fele replied on Thu, Jan 28 2010 4:15 PM
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.



Top 25 Contributor
Posts 312
JonnyBee replied on Fri, Jan 29 2010 12:18 AM
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. 
Jonny Bekkum, Norway CslaContrib Coordinator
Top 500 Contributor
Posts 25
Fele replied on Fri, Jan 29 2010 9:18 AM
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.


Page 1 of 1 (6 items) | RSS

Please contact Magenic for your .NET consulting
and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems