New version of ObjectListView in CSLAcontrib

New version of ObjectListView in CSLAcontrib

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


Brian Criswell posted on Friday, August 18, 2006

I have updated the ObjectListView in CSLAcontrib.  This version holds a list of ObjectView objects.  The ObjectView implements IEditableObject so that it can buffer changes made by a DataGridView (similarly to how DataView and DataRowView work).  This version also includes an IncludeDefault property, which inserts a default item at index 0.  The downside of IncludeDefault is that it uses Activator.CreateInstance to create the default item.  So if your object in your list requires a non-default constructor to be used, there could be problems.

Future development will include an interface that an object can implement to alter sort values, and a corresponding event on the ObjectListView if the object does not implement the interface.  I will also look at means of suppressing exceptions thrown by the default item.

mr_lasseter replied on Friday, September 22, 2006

Brian,

Is there any documentation on using this anywhere?  I created a project to build the ObjectListView and added a form to the project.  When I try to add the ObjectListView to the form I get the following error:

Failed to create component 'ObjectListView'. 

'System.MissingMethodException:  Constructor on type 'Csla.ObjectListView' not found.

Any ideas on what I am doing wrong?

Brian Criswell replied on Friday, September 22, 2006

It looks like this is my next bug fix.  The ObjectListView does not have a default constructor and does not allow you to change the list after it has been created.  It looks like I will need to change this.  For the time being you will have to just create it in code.  I will work on this over the weekend.

As for documentation, you should be able to use this just like a DataView (or as close as possible) except that this works with IList objects instead of DataTables.  So the DataView would be the place to get documentation.  If it does not behave similarly to the DataView, I have probably done something wrong.

The major difference is that the ObjectListView can have a default item.  This item is always visible and never sorted (it is always at index 0).  You can use it in a manner similar to the following:

ObjectListView view = new ObjectListView(someIList);
view.IncludeDefault = true;
view[0]["SomeProperty"] = 10;
view[0]["AnotherProperty"] = "A description";

If you have any other questions, feel free to post them.

mr_lasseter replied on Friday, September 22, 2006

I guess I misunderstood what this was.  I thought it was a listview control that supported databinding.  The name threw me off.

Brian Criswell replied on Friday, September 22, 2006

No, it is a view onto a list of objects.  I have done a data-bindable ListView in the past, built off of one of Rocky's examples, but unless you need grouping, I would suggest using the new DataGridView control.  You can modify its appearance so that it looks and acts almost exactly like a ListView.

Copyright (c) Marimer LLC