Extending IEnumerable to Return BindingList

2019-08-08 15:26发布

In a previous question on Stack Overflow, I had run into an issue with returning an EF query to the DataGridView. Of course I'd run into an issue. However, I added an extension method that still has me baffled since it isn't working. It seems like it should, but for some reason it's not.

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 what's going on? My implementation is like so:

MyEntities context = new MyEntities();
tempDataGridView.DataSource = context.Employees.ToBindingList();

1条回答
做个烂人
2楼-- · 2019-08-08 15:40

Got it. As Ecyrb had suggested in a previous post, the BindingList does not sort. I did use the suggested site/ to get my list to sort. Thanks guys! My extension does work now.

查看更多
登录 后发表回答