属性 用于 BindingSource 到 return 按字母顺序排序的列表
Property for BindingSource to return alphabetically sorted list
我正在尝试按字母顺序创建一个 属性,returns 一个 BindingSource
,此处按 "Name" 列。下面是一个使用 Linq 的镜头,它没有编译:'BindingSource does not contain a defintion for 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>;
}
}
我只是在猜测,但试试这个:
List <Contractor> SortedList = bsContractors.List.Cast<Contractor>().OrderBy(o => o.Name).ToList();
我正在尝试按字母顺序创建一个 属性,returns 一个 BindingSource
,此处按 "Name" 列。下面是一个使用 Linq 的镜头,它没有编译:'BindingSource does not contain a defintion for 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>;
}
}
我只是在猜测,但试试这个:
List <Contractor> SortedList = bsContractors.List.Cast<Contractor>().OrderBy(o => o.Name).ToList();