DataGridView Not Bind IEnumerable<TResult> but does List<TResult>
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. Wha开发者_高级运维t is the problem?
The DataGridView
DataSource
property can be any object that implements one of these interfaces: IList
, IListSource
, IBindingList
or IBindingListView
, which List<T>
does, but IEnumberable<T>
doesn't. Reference: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource.aspx
精彩评论