First attempt at IBindingListView

First attempt at IBindingListView

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


Brian Criswell posted on Thursday, June 22, 2006

I ported the old FilterableCollectionBase to CSLA 2.0, but it and the SortedBindingList together raised too many ListChanged events, especially resets.  So I finally decided to give IBindingListView a go and wrote my first attempt over the last weekend.  It works similarly to SortedBindingList in that it takes an IList<T> as a parameter.

I really have only tested the sorting by 1 property and filtering, but I thought that some people might like to give it a go.  So the provisos are that add, remove and the like have not been tested (my use case has me manipulating the source lists).  The ObjectListView autosorts and autofilters, but it tries to do it in as economical a manner as possible.  So an ItemChanged event on the source might generate an ItemMoved event, or an ItemAdded or ItemDeleted if the change causes the item to be filtered or unfiltered.

I am also going to start optimising where I can.  The sorting is done by hand, but I cheated on the filtering (no way am I going to write a parser of that complexity).  Internally, there is a single row DataTable with a DataView.  Whenever an item needs to be evaluated as to whether it is filtered, its contents are copied into the row and the DataView is checked to see what the row count is.

If you plan on using this for in place editing while using a filter, I imagine that you would need to add "OR IsNew = 'True'" to the filter end of the to keep the new items from being filtered out.

So, in short, it is not completely tested, but I thought some people might like to play with it now and know that it is on its way rather than not know that something was available and coming.

Brian Criswell replied on Friday, June 30, 2006

After using it for a week, I think I have most of the bugs out.

tsmo replied on Friday, July 21, 2006

Found a bug:  if you try to create an ObjectListView<T> where T has a nullable property, such as a Nullable<DateTime>, the _filteredTable will throw an exception when trying to set up the columns, saying that DataSet doesn't support Nullable<T>.

Chances are you've looked at them already, but there are a couple other people trying to implement IBindingList out there, so if you're looking to find a way to do this without using DataTables for filtering, you might be able to find ideas here:

http://www.gotdotnet.com/workspaces/workspace.aspx?id=ccbb6b50-6c55-4291-b191-f5c5f80ba122
http://book.itzero.com/read/microsoft/0602/Addison.Wesley.Data.Binding.with.Windows.Forms.2.0.Programming.Smart.Client.Data.Applications.with.dot.NET.Jan.2006_html/032126892X/ch09lev1sec13.html

Thanks for a great object-- I look forward to the day when its bulletproof and can replace SortedBindingList in CSLA.

tsmo

Brian Criswell replied on Sunday, July 23, 2006

Thanks for the feedback.  The next version will return an ObjectView when indexed instead of an object of type T.  This is to properly support the DataGridView control.

Copyright (c) Marimer LLC