New version of ObjectListViewNew version of ObjectListView
Old forum URL: forums.lhotka.net/forums/t/822.aspx
Brian Criswell posted on Friday, August 04, 2006
After various chats on this forum with Rocky and others regarding aspects of SortedBindingList and why it did not work similarly to the DataView when it was bound to a grid, I tried using my ObjectListView in a DataGridView and watched as the possessed control sorted and bounced rows around if you just looked at it funny.
So I did some research into why the DataView acts the way it does (waits until you move off of a row before sorting the row), and I discovered that it was because of the DataRowView. The DataRowView implements IEditableObject and acts as a buffer for the underlying DataRow. With that knowledge in hand, I added an ObjectView to the solution and changed the ObjectListView to present a list of ObjectView objects. I have tried to duplicate the interface and behaviour of DataView as much as possible, although I imagine that I have still botched some of it.
What this does mean is that the ObjectListView is no longer generic in nature. I may still implement a generic version that inherits from this one, but I am not sure how much you would gain from it as the only thing that would change is that ObjectView.Object would return type T. The gain from this is you should now be able to use any IList (including an array?) as the source list.
The two things I still want to add are the ability to swap one IList for another as the source list (rather than having to create a new ObjectListView, should be fairly easy) and add a mechanism for swapping one sort property for another. This would allow you to sort by a read-only date if the list is asked to sort by the string representation of the date (the perennial issue with SmartDate). I am looking for ideas on how to implement this. One method I have looked at is adding attributes to properties, but that does not work if you code generate properties in a base class and do not allow the properties to be inherited from in the derived class. It would also not help in the case of an array or other list that you cannot alter the source code. So I have been leaning toward allowing objects to implement an interface that would provide a list of properties and the alternate properties to sort by. The ObjectListView would use that interface if it existed on the source list or allow it to be set on the ObjectListView if the source list did not implement the interface.
I am open to suggestions on this or how the rest of the ObjectListView works. It would also be nice if people could report bugs and give other feedback. When I feel that it is working bug free enough, I will post the new version to CSLAcontrib.
Edit: Updated to the version that can have a default item.
xal replied on Friday, August 04, 2006
Brian,
I did something quite a while ago that solves a lot of problems with sorting. I did it on the old SortedView and on the current SortedBindingList. It's simple and it works. It would probably be best if we had some attributes for this, but since it's hard to standarize that, this is a very workable solution.
It's only consists of adding an event to the list.
Take a look at this thread in the old forum (message 12):
http://groups.msn.com/cslanet/general.msnw?action=get_message&mview=0&ID_Message=24363
Andrés
Brian Criswell replied on Saturday, August 05, 2006
I have updated the attached file to fix a bug with GetEnumerator() calling itself and causing a stack overflow. I had forgotten to change it after removing the generic methods from the ObjectListView.
Edit: After using it a bit in another program, I have refined the filtering (was not working) and the use of the ListChanged.ItemChanged event.
Brian Criswell replied on Sunday, August 13, 2006
I have posted a new version that can include a default item as the first item in the ObjectListView. This default item cannot be sorted or deleted, and it will only work for source lists that contain a type with a default constructor.
I have also been thinking about the custom sorting issue some more, and I really like Xal's solution as a generic solution, but I also want to give the object the opportunity to decide its own custom sorting. So I will most likely add an interface that an object can implement to convert a sort value and add the sort event to ObjectListView.
So, any thoughts about either of these items? Has anyone even tried the ObjectListView...?
FireGarden replied on Monday, August 14, 2006
Where do I find information about using the ObjectListView? I have downloaded the class and it looks good to use. But I haven't started using it.
Rob
Brian Criswell replied on Monday, August 14, 2006
You would use it similarly to a DataView but for classes that implement IList instead of a DataTable.
FireGarden replied on Monday, August 14, 2006
Could I use an ObjectListView to create a filtered version of a Csla.NameValueListBase?
I would filter a NameValueList by it's ParentID and use it to populate a collection of TreeNodes.
Rob
Copyright (c) Marimer LLC