这是我的代码
bindingSource1.CurrencyManager.AddNew();
int dtCode = dsData1.Item.AsEnumerable().Where(x => x.DataCode == txtItem.Text).Count();
if (dtCode == 0)
{
DataRowView dr = (DataRowView)bindingSource1.CurrencyManager.Current;
dr["DataCode"] = txtItem.Text;
dr["Quantity"] = dtQuantity+1;
}
else
{
//insert code for update
}
bindingSource1.CurrencyManager.EndCurrentEdit();
有人可以代替它
我的想法是仅显示突出显示的行,并且每当要输入另一个商品代码“ axe”时,数量+1
答案 0 :(得分:0)
发现此代码
DataRow rv = (from fr in dsData1.Item.AsEnumerable()
where fr.Field<string>("DataCode") == txtItem.Text
select fr).FirstOrDefault();
if (rv != null)
{
rv["Quantity"] = Convert.ToDecimal(rv["Quantity"]) + 1;
}
else
{
bindingSource1.CurrencyManager.AddNew();
DataRowView dr = (DataRowView)bindingSource1.CurrencyManager.Current;
dr["DataCode"] = txtItem.Text;
dr["Quantity"] = 1;
bindingSource1.CurrencyManager.EndCurrentEdit();
}