DataGridView 未绑定 IEnumerable但 List确实如此
我已经编写了这段代码:
public List<TResult> SelectAll<TResult>(Func<Regions, TResult> selector) where TResult : class
{
using (RepositoryDataContext = new DataClasses1DataContext())
{
return RepositoryDataContext.Regions.Select<Regions, TResult>(selector).ToList<TResult>();
}
}
并以这种方式从表单调用它:
dgvFindFirst.DataSource = clsr.SelectAll<SelectAllRegion>(MY SELECT LAMBDA EXP);
但是当编写这样的方法时:
public IEnumerable<TResult> SelectAll<TResult>(Func<Regions, TResult> selector) where TResult : class
{
using (RepositoryDataContext = new DataClasses1DataContext())
{
return RepositoryDataContext.Regions.Select<Regions, TResult>(selector).AsEnumerable<TResult>();
}
}
DataGridView Not Bound any Nothing 返回。 问题是什么?
I've written this code:
public List<TResult> SelectAll<TResult>(Func<Regions, TResult> selector) where TResult : class
{
using (RepositoryDataContext = new DataClasses1DataContext())
{
return RepositoryDataContext.Regions.Select<Regions, TResult>(selector).ToList<TResult>();
}
}
and call it from the Form this way:
dgvFindFirst.DataSource = clsr.SelectAll<SelectAllRegion>(MY SELECT LAMBDA EXP);
but when write a method like this :
public IEnumerable<TResult> SelectAll<TResult>(Func<Regions, TResult> selector) where TResult : class
{
using (RepositoryDataContext = new DataClasses1DataContext())
{
return RepositoryDataContext.Regions.Select<Regions, TResult>(selector).AsEnumerable<TResult>();
}
}
DataGridView Not Bound any Nothing returns.
What is the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DataGridView
DataSource
属性可以是实现以下接口之一的任何对象:IList
、IListSource
、IBindingList
或IBindingListView
,List
可以,但IEnumberable
不会。参考: http://msdn.microsoft.com /en-us/library/system.windows.forms.datagridview.datasource.aspxThe
DataGridView
DataSource
property can be any object that implements one of these interfaces:IList
,IListSource
,IBindingList
orIBindingListView
, whichList<T>
does, butIEnumberable<T>
doesn't. Reference: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource.aspx