views:

323

answers:

2

I have an EF source that I'm binding to a DataGridView. The binding is happening programatically. However, the sorting is not working.

So I decided to mess with some code and create an Extension Method, but it seems like its still not working.

public static class BindingListEntityExtension
{
    public static BindingList<T> ToBindingList<T>(this IEnumerable<T> entities)
    {
        BindingList<T> rtn = new BindingList<T>();

        foreach (T obj in entities)
        {
            rtn.Add(obj);
        }

        return rtn;
    }
}

Any ideas?

+1  A: 

The data binding relies on the IBindingList interface for filtering and sorting, and this interface is not implemented by your EF source. To enable sorting this data source, you would have to create a wrapper that implements IBindingList.

Thomas Levesque
Not working for me yet.
Jason N. Gaylord
+2  A: 

I ran across this article for a SortableBindingList<T>. Works great. You may be able to figure out how to get your extension method working by checking out the source.

Ecyrb