CSLA .NET

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

Xaml binding to sorted list

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

Top 500 Contributor
Posts 27
daniel_higgins Posted: Sun, Nov 23 2008 11:22 PM

Hi All,

Does xaml binding to a sorted wpf view work in csla 3.5?

In c#, I tried:

ICollectionView view = CollectionViewSource.GetDefaultView(parent.ChildCollection);

view.SortDescriptions.Add(new SortDescription("Ordinal", ListSortDirection.Ascending));

And it failed. When I looked at *view* in the debugger, its CanSort property was false.

Am I barking up the wrong tree here?

Top 500 Contributor
Posts 27

Hi

In the non-csla samples I've looked at, using the SortDescriptions on a collection and setting the ItemsSource="{Binding ChildCollection}" in Xaml seemed to work pretty well. When I added a new item to the child collection, the new item shows up in the list box.

In csla, adding a SortDescription to the default collection view (as per wpf examples I've read), does not appear to work.

So I used the csla linq features:

listBox.ItemsSource = from c in parent.ChildCollection orderby c.Ordinal select c;

That gives me a sorted list. When I add a new item to the collection (parent.ChildCollection.AddNew()), it does not appear in the list box. I thought the linq equipment in csla returned a "hot list" that was tied to the underlying collection.

So, I suppose I have two questions:

1. Does the wpf CollectionView and SortDescriptions stuff work on csla collections?

2. If I cannot use the CollectionView/SortDescriptions stuff, and I instead use linq on clsa, do I need to un-and-re-bind to linq query result? Perhaps I am using the wrong linq expression?

Thank you

Top 200 Contributor
Posts 40
JZuerlein replied on Tue, Dec 9 2008 12:08 AM

I don't think the CollectionView stuff works with CSLA.  My guess is because CSLA collections don't allow sorting.  There is a class called SortedBindingList<T> that is used to provide this functionality.  It is described in detail in the 2005 business objects book.

Top 500 Contributor
Posts 27

Thanks for the reply Jeff.

I was able to get the effect I wanted by using

ListCollectionView myView = new ListCollectionView(parent.ChildCollection);

then applying the SortDescriptions to this new ListCollectionView. I guess the DefaultCollectionView is not sortable.

It likely has something to do with the differences between BindingList and ObservableCollection, but I had to call myView.Refresh() every time I added a new child to the collection (parent.ChildCollection.AddNew()).

Page 1 of 1 (4 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