Entity Framework 4.0 Databinding with sorting not working

Posted by Mike Gates on Stack Overflow See other posts from Stack Overflow or by Mike Gates
Published on 2010-04-23T22:59:38Z Indexed on 2010/04/23 23:03 UTC
Read the original article Hit count: 770

Filed under:
|

I want to do something that I thought would be very simple. I want to bind a generated Entity Framework EntityCollection to a WPF DataGrid. I also want this grid to be sortable.

I have tried all kinds of things to make this happen, including using a CollectionViewSource. However, nothing seems to work. Using a normal CollectionViewSource around the EntityCollection gives me:

'System.Windows.Data.BindingListCollectionView' view does not support sorting.

Ok...strange. I would have thought this would work. Next on the CollectionViewSource, I try setting:

 CollectionViewType="ListCollectionView"

Great, sorting now works. But wait, I can't add or remove entities using the grid now, presumably because ListCollectionView doesn't support this with an entity framework context.

So, I guess I need to capture events coming out of the datagrid in order to add or remove entities manually from my context. Now I can't find an event to capture to detect an add...!

Why is this so hard? This should be the standard "demo" case that Microsoft should have designed around.

Any ideas?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about entity-framework