0
它绑定到WPF的ListView,使用ItemsSource="{Binding Path=ProductList}"
:更新和删除列表视图排
private ObservableCollection<SalesItem> _ProductList = new ObservableCollection<SalesItem>();
public ObservableCollection<SalesItem> ProductList { get { return _ProductList; } set { _ProductList = value; } }
插入新行的ListView:
SalesItem item = new SalesItem { Picture = product.Picture, ProductName = product.Name, Quantity = 1, TotalPrice = product.Price };
ProductList.Add(item);
现在我想update the quantity, and price, if the quantity is zero, remove from list
:
List<SalesItem> salesItems = (from SalesItem items in this.dgProductList.ItemsSource
select items).ToList<SalesItem>();
foreach (SalesItem salesItem in salesItems)
{
if (salesItem.ProductName == cbMultiProductList.Text.Trim())
{
// Increase item quantity
salesItem.Quantity = salesItem.Quantity + 1;
}
}
谢谢。
编辑:
SalesItem
是EF代码第一个模型。
试过了,问题是他新的行会追加到最后一行:
ProductList.Remove(salesItem);
ProductList.Add(salesItem);
谢谢,我该如何实施它没有触摸salesItems模型。 – Alvin
如果没有'INotifyPropertyChanged',你不能实现它。另一种方法是让你明确地检查每次数量设置为零,你应该调用foreach循环,哪一个课程是不好的progarmming。 –
问题是SalesItems是代码优先模型。 – Alvin