Extending IEnumerable to Return BindingList

陌路散爱 提交于 2019-12-24 14:16:17

问题


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:


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.



来源:https://stackoverflow.com/questions/1396256/extending-ienumerable-to-return-bindinglist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!