将实体绑定到Windows DataGridView [英] Binding Entities to a Windows DataGridView

查看:166
本文介绍了将实体绑定到Windows DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个EF源,我绑定到一个DataGridView。绑定正在程序上发生。但是,排序不起作用。



所以我决定混淆一些代码并创建一个扩展方法,但它似乎仍然不起作用。

  public static class BindingListEntityExtension 
{
public static BindingList< T> ToBindingList< T>(该IEnumerable< T>实体)
{
BindingList< T> rtn = new BindingList< T>();

foreach(实体中的T obj)
{
rtn.Add(obj);
}

return rtn;
}
}

任何想法?

解决方案

我碰到这个 SortableBindingList< T> 的文章。工作很棒您可以通过查看源代码来找出如何使扩展方法正常工作。


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?

解决方案

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.

这篇关于将实体绑定到Windows DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆