我正在尝试创建一个按字母顺序返回BindingSource
的属性,此处是“Name”列。下面是使用Linq的镜头,它没有编译:'BindingSource不包含OrderBy的定义'
我不知道如何实现这一点,Linq或其他 你有什么建议?
internal System.Windows.Forms.BindingSource bsContractors;
this.bsContractors = new
System.Windows.Forms.BindingSource(this.components);
public System.Collections.Generic.List<Contractor> Contractors
{
get
{
// Linq
List < Contractor > SortedList = bsContractors.OrderBy(o => o.Name).ToList();
bsContractors.DataSource = SortedList;
return bsContractors.List as System.Collections.Generic.List<Contractor>;
}
}
答案 0 :(得分:1)
我只是在这里猜测,但试试这个:
List <Contractor> SortedList = bsContractors.List.Cast<Contractor>().OrderBy(o => o.Name).ToList();