I hereby nominate ObjectListView... new entries are welcome

I hereby nominate ObjectListView... new entries are welcome

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


FireGarden posted on Saturday, August 26, 2006

If you have not yet downloaded ObjectListView you should. Its available here:

http://www.codeplex.com/SourceControl/DownloadSourceCode.aspx?ProjectName=CSLAcontrib&changeSetId=3610

It allows you to easily filter and sort business collections. A good example of where I use it is in populating a TreeView control. The problem with populating a treeview control is in populating the children.

Typically all children come from the same table but have a differnt parent id. ObjectListView makes it easy to filter the children collection by parent id and sort it. This filtered list is what is used to generate the appropreiate child notes on the tree for that parent id.

Filtering & sorting is so simple because out of the box you can filter by any public property exposed by the underlying BusinessList object.

Are there any alternatives to using ObjectListView that I don't know about to get a filtered & sorted view of an IList / BO?

Regards,

Rob Wheeldon

dean replied on Sunday, August 27, 2006

Rocky's SortedList(of t) and FilteredList(of t) in csla 2.1 are working pretty well but I haven't tried objectlistview for comparison purposes.

Dean

david.wendelken replied on Sunday, August 27, 2006

Maybe I'm using it wrong (and that's not unlikely!), but I don't really like using SortedBindingList.

In an unsorted form, I cache the collection object.  That cached object is passed to the grid and it is also available for use in various events that I might raise in the form.

When I return a SortedBindingList instead of the object collection and cache it, I can pass it to the grid just fine.  But it is useless for handling any object-specific events.  At least it is to me, because I can't find a way to "un-cast" it back to the original object its sorting.

So, my questions are:

1) Does using ObjectListView have the same problem?

2) How could I use SortedBindingList so I don't have that problem?  (Cache both the object collection and the sortedbindinglist?)

xal replied on Sunday, August 27, 2006

You could create the sortedbindinglist just to bindo to the grid and pass the collection to whereever it is you use it... the sortedbl and the other objects will be linked to the same list, and any changes you make there will be impacted in both places, because the reference is the same.
Sorting is <with some exceptions> more of a UI thing, so it's perfectly normal to just create the sorted list just to bind to your grid.

Anyway, you can still add / remove / edit items from the sorted list. You could also have a property in your bo that returns a sorted list for your current list. That way you can pass around the original list and still use the sorted list whenever you find that neccesary...

Andrés

FireGarden replied on Sunday, August 27, 2006

Object List View is passed a reference to your BO upon creation

new ObjectListView(Business.Accounts.GetAccounts(), "GroupID=" + accountGroupInfo.ID)

This example is an overload with a filter passed in as the second parameter. You can filter and sort the OLV. It sounds like the 2.1 solution uses two differnt objects to accomplish this? SortedList & FilteredList(of t)?

The ObjectListView then subscribes to the BO list changed event:

_iBindingList = (IBindingList)list;

_iBindingList.ListChanged += new ListChangedEventHandler(_iBindingList_ListChanged);

ObjectListView is now ready to use in you UI databinding and will raise an event when the business object changes. Subscribe to the OLV event from your UI control and implement the apropreiate refresh.

_list.ListChanged += new ListChangedEventHandler(_list_ListChanged);

As a specific example I use this event to update the nodes in a treeview based on the ListChangedEventArgs e class.

switch (e.ListChangedType)
case ListChangedType
.ItemAdded:
case ListChangedType
.ItemDeleted:
case ListChangedType.ItemMoved:

Regards,

Rob Wheeldon

 

Copyright (c) Marimer LLC