Jason N. Gaylord
Jason N. Gaylord

Reputation: 8324

Binding Entities to a Windows DataGridView

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?

Upvotes: 3

Views: 1879

Answers (2)

Ecyrb
Ecyrb

Reputation: 2080

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.

Upvotes: 3

Thomas Levesque
Thomas Levesque

Reputation: 292615

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.

Upvotes: 1

Related Questions