Silverlight CollectionViewSource page filtering is not allowed during add/edit

Here’s project scenario, editable collection view bound to a list box, upon selecting an item it populates the Data Form control (in my testing I tried the Silverlight toolkit and the Telerik Rad controls.) On the list I have a CollectionViewSource filter method.

What would happen, if you would place the form into edit mode, then execute the filter method you will get an error that filter cannot be done while in AddNew or Edit mode.

To solve this you can detect if the collection is in one of those modes and either confirm or cancel the changes.

if (MyCollection is IEditableCollectionView)
{
    var MyCollectView = MyCollection.View as IEditableCollectionView;

    if (MyCollectView.IsAddingNew)
    {
        MyCollectView.CommitNew();
    }
    if (MyCollectView.IsEditingItem)
    {
        MyCollectView.CommitEdit();
    }
}
Advertisements
This entry was posted in Silverlight, Web and tagged . Bookmark the permalink.

3 Responses to Silverlight CollectionViewSource page filtering is not allowed during add/edit

  1. Thanks for your share, I encountered on DataForm and recently on a DataGrid. And we do not need to Refresh a filter or sorting for each property.
    PropertyChangedEventHandler filter = (sen, arg) => {
    if(typeof(ICheckableItem).GetProperties().ToList().Select(pi=>pi.Name).Contains(arg.PropertyName))
    Filter();
    };

  2. Selena says:

    Hi there, I discovered your website via Google while looking for a comparable subject, your site got here up, it seems great.
    I have bookmarked it in my google bookmarks.
    Hi there, simply turned into aware of your weblog thru Google, and found that
    it’s truly informative. I’m gonna watch out for brussels.
    I will appreciate when you continue this in future.
    Lots of people might be benefited from your writing. Cheers!

  3. I am regular reader, how are you everybody? This piece of
    writing posted at this site is truly nice.

Comments are closed.