private void btnNew_Click(object sender, RoutedEventArgs e) { ProductBindEntity item = new ProductBindEntity(); item.SerNumber = ocProduct.Count > 0 ? ocProduct.Max(x => x.SerNumber) + 1 : 1; item.UpdatableFlag = true; //允许更改编辑类型 item.SetEditState(EditState.New); //设置编辑状态为新增 this.listProduct.Add(item); //更新缓存数据 this.ocProduct.Add(item); //更新绑定数据源 //选中新增的行,并滚动到该行 this.dgProductData.SelectedItem = item; this.dgProductData.ScrollIntoView(item); }
//删除选择的项 private void deleteProductSel() { if (this.dgProductData.SelectedItem == null) { MessageBox.Show("请选择要删除的项", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information); return; } ProductBindEntity item = this.dgProductData.SelectedItem as ProductBindEntity; if (item.EditState == EditState.New)//新增的直接移除 { this.listProduct.Remove(item); } else { //更改编辑类型为Deleted item.SetEditState(EditState.Deleted); } this.ocProduct.Remove(item); //从数据源移除 this.updOcProductBindSn(); //更新行号 }