PagedCollectionView and DataForm. IList required to get Add/Delete button

Sep 11, 2010 at 10:45 PM
Edited Sep 11, 2010 at 10:47 PM

When binding the Silverlight DataForm to a PagedCollectionView, the new/delete (+/-) buttons will be disabled unless the Collection is based on a IList.

The Silverlight Dataform is very useful, but not without the Add/Delete button.

In your ViewModel, the PagedCollectionView is created directly from the EntitySet, which is not implementing IList.

My dataform i currently bound to this Collection in the ViewModel:

public PagedCollectionView ReleaseList { get; private set; }
void setupReleaseListCollection()
List<Release> releaselist = new List<Release>(dataService.ReleaseList);            
ReleaseList = new PagedCollectionView(releaselist);            

using (ReleaseList.DeferRefresh())          

DataForm is working fine, including edit, but there is not Add/Delete button. This article,, cover this in details, including a suggested fix to the issue.

I did try this approach in my own viewmodel implementation, but with mixed sucess. I did get the Add button in the DataForm, but no data showed up in the form (Release Collection was empty).

List<Release> releaselist = new List<Release>(dataService.ReleaseList);
ReleaseList = new PagedCollectionView(releaselist);

I also tried this one - with the same result:

ReleaseList = new PagedCollectionView(dataService.ReleaseList.ToList());

Sep 12, 2010 at 3:19 AM

I would definately look at this discussion here:

What I understand from the discussion is that the Add/Delete is not completely clear - are you adding/deleting items to the view, or inserting/deleting from the database.  I believe I understand your view point would be to insert/delete from the database; however, since we are viewing a (potentially filtered) view of the data, I do see where this implementation on PCV wrapping an EntitySet could be tricky.

I believe that this is easly solved with the MVVM-S toolkit by using a command, which has a simple 1 line of code behind it to insert / delete records in the underlying entityset.  Since the PCV is just a wrapper over that, the only other thing you might consider is changing the current item (e.g. user clicks new item button > this inserts into DB, then sets the current item in the PCV to this new item).

I have expressed this in the context of another conversation that I have been involved with regarding an MVVM-friendly domain data source (which potentially would replace the PCV in many scenarios).  Perhaps we will see this in the public exposure of an EntityCollectionView (or some such DDS-type View object).  If you would like to weigh-in on this discussion it is available here:

Sep 12, 2010 at 12:05 PM

Thanks again.

To clarity, I am adding/deleting items in the PagedCollectionView, and not the database. I will still persist using the current MVVM-S ViewModel commands (the likes of CmdSave and similar in your demo code).

The problem is, DataForm does not show Add/Delete tools for managing the items in the PagedCollectionView unless the Collection is created with data supporting IList.

Hope that helped for clarification.