原本,用了order,程序卻沒有進行排序
dgrdDefinedMaterial.DataSource = RecipeDetailModel.MaterialDefinedList.OrderBy(e => e.Name).ToList();
修改後
RecipeDetailModel.MaterialDefinedList = RecipeDetailModel.MaterialDefinedList.OrderBy(e => e.Name).ToList();
原因:
因為用的是 dgrdDefinedMaterial.DataBindings.Add("DataSource", recipeDetailModel, "MaterialDefinedList");綁定,
那麼在對象
private List<MD_Material> materialDefinedList;
[DataMember]
public List<MD_Material> MaterialDefinedList
{
get { return materialDefinedList; }
set
{
materialDefinedList = value;
NotifyPropertyChanged("MaterialDefinedList");
}
}
使用dgrdDefinedMaterial.DataSource = RecipeDetailModel.MaterialDefinedList.OrderBy(e => e.Name).ToList();這個的時候,
dgrdDefinedMaterial.DataSource裡面進行了排序,但是 RecipeDetailModel.MaterialDefinedList卻沒有,
所以要對 RecipeDetailModel.MaterialDefinedList 重新賦值排序後的