Yes, SortedBindingList is designed to act as a live, editable "view" over any IList<T>.
The new FilteredBindingList coming in 2.1 will do the same thing, but acting as a filter instead.
And since they both implement IList<T> themselves, they'll be stackable - which I find very cool:
List<string> list = new List<string>();
FilteredBindingList<string> f = new FilteredBindingList<string>(list);
f.ApplyFilter("Rocky");
SortedBindingList<string> s = new SortedBindingList<string>(f);
s.ApplySort();
The result displays only items containing "Rocky" and in sorted order
How am i going to filter multiple values in a property?
From: brembot [mailto:cslanet@lhotka.net]
Sent: Monday, December 11, 2006 8:27 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Sorting / Filtering EditableRootList
Ex. StudentNo Like "1,5,7"
If you pass Nothing/null for the property name, then the business object itself is passed into your filter method as the item parameter.
If the caller needs to dynamically specify the property names to use, you can just make your filter parameter (the second parameter) a more complex object that contains both the list of property names and the list of other filter criteria.
RockfordLhotka:Yes, SortedBindingList is designed to act as a live, editable "view" over any IList<T>.
The new FilteredBindingList coming in 2.1 will do the same thing, but acting as a filter instead.
And since they both implement IList<T> themselves, they'll be stackable - which I find very cool:
List<string> list = new List<string>();
FilteredBindingList<string> f = new FilteredBindingList<string>(list);
f.ApplyFilter("Rocky");
SortedBindingList<string> s = new SortedBindingList<string>(f);
s.ApplySort();The result displays only items containing "Rocky" and in sorted order
Hello Rocky,
I am trying to filter out an Editable List Object and bind it to the the grid but the ApplyFilter() method signature requires two Paramterers.Is there something I am missing?I want to filter a list by just a string and I do not want to create another object and pass the criteria object to it.Any thoughts on this?
Thanks in Advance
V
Inquistive_Mind:I am trying to filter out an Editable List Object and bind it to the the grid but the ApplyFilter() method signature requires two Paramterers.Is there something I am missing?I want to filter a list by just a string and I do not want to create another object and pass the criteria object to it.Any thoughts on this?
This is suppored - just pass string.Empty or "" as the property name. That'll result in the filter running against the ToString() value of the entire object. So as long as your object puts the appropriate values into its ToString() output you are all set.
The only alternative is to write your own custom filter method, so it could be aware of all the different properties of your specific object and how you want to deal with them.
I suppose you could try back-porting FilteredBindingList into
CSLA 2.0.
Or you can look at CSLAcontrib on CodePlex, as there’s a contribution
there that may help (ObjectListView or something like that?)
Rocky
Yes it is correct.
No you cannot sort on multiple columns with it.
I use the ObjectListView instead - it does sorting and filtering on multiple columns.
It is available for free in the CSLA Contrib download section.
Check old posts here for samples on how to use it.
Oh - and once you move up to .Net 3.5 you can use LINQ to do sorting and filtering. I haven't got there yet. Maybe around Xmas I can move in to the modern world - nice way to end the year!
Joe
It is true that the implementation is relatively simplistic.
On codeplex there’s a more complex implementation.
But I think the real answer is LINQ to CSLA, and so I view
SortedBindingList and FilteredBindingList as effectively obsolete at this point.
Rocky
I'm using Csla 3.5.2 and I am trying to wean myself off of the SortedBindingList and FilteredBindingList and to use Linq instead. I'm hitting a bit of a snag though. When using a SortedBindingList, any change I make to the original BLB collection is immediately reflected in the SBL including adding and removing items. On the other hand, when I use Linq if I add or remove from the underlying collection the change does not appear automatically. I need to maunally re-run the Linq query to see the changes. Is there a way to have the collection returned by the Linq query to work dynamically?
Old Way
SortedBindingList<ShippingWeightTableItem> sbl = new SortedBindingList<ShippingWeightTableItem>(WeightTable);New Way
bindingSource2.DataSource = from w in WeightTable orderby w.Weight ascending select w;
If you use "regular" LINQ to Objects then the result is IEnumerable(Of T) and it is not "linked" (pun intended) to the source collection.
If you use LINQ to CSLA then the result is a collection of the same type as the source and the two are linked so that changes in the result are reflected in the source.
I am not sure which version of CSLA this appears in first. 3.5 or 3.6.
Joe
The Expert C# 2008 Business Objects book has an entire chapter
(14) devoted to LINQ to CSLA.
LINQ to CSLA has two features:
1.
When doing a non-projection query against a BLB you get back a
LinqBindingList<T> instead of an IEnumerable<T>. The
LinqBindingList class is much like SortedBindingList or FilteredBindingList, in
that it is a live view over the real BLB you started with. This means if you
add/remove items from the result of the query, they are added/removed in the
real BLB too.
2.
Indexed queries against a BLB. If you mark a child object’s
property with the Indexable attribute, and then use that property in the where
clause of a LINQ query against the list, CSLA will create an index against that
property and will use the index for the query. This is great if you do numerous
queries against a single instance of a large list – in which case you can
get many orders of magnitude better performance. If you don’t do multiple
queries against a single large list, it is actually counter-productive, because
creating the index is more expensive than the benefit of using it.
No examples of using it are really needed, because it just
works. There’s no special syntax or special effort on your part. If you
do a non-projection query against a BLB, you get a LBL<T> back. If you
put the Indexable attribute on a child property, and use that property (alone)
in a where clause, you’ll get indexing.
Rocky
I'm trying to figure this out as well....
I have to filter on a property that is of type enum. The filter doesn't seem to work on anything but a string and when I create a custom filter function.. it sets both params as the filter value.
If I find an answer I will post it for ya :).
Has a solution the the structure problem been discovered yet? I am trying to filter based on a Guid (as I suspect others may want to do) but it doesn't seem to work out-of-the-box.
The error I get is: "System.InvalidCastException: Conversion from type 'Guid' to type 'String' is not valid."
What is the preferred work-around?
Thanks in advance,
Mike
In case anyone else is having a bit of trouble with Enums/Structures/Guids and filtering, I may have a solution:
Public Shared Function Filter(ByVal item As Object, _
ByVal filterValue As Object) As Boolean
Dim result As Boolean = False
If item IsNot Nothing AndAlso _
filterValue IsNot Nothing Then
result = item.ToString.Equals(filterValue.ToString)
End If
Return result
End Function
It works like a charm for me and I can't find a problem with it but of course that doesn't mean there isn't a problem. Feedback would be appreciated.
Mike
Copyright (c) Marimer LLC