C# 在c中重置绑定#
这是我的密码员。我刚刚为我的收据创建了一个新类。 此代码用于添加按钮C# 在c中重置绑定#,c#,C#,这是我的密码员。我刚刚为我的收据创建了一个新类。 此代码用于添加按钮 else if (!string.IsNullOrEmpty(cmbProductName.Text) && !string.IsNullOrEmpty(txtQuantity.Text)) { Receipt obj = new Receipt() { Id = order++, ProductName = Convert.ToString(cmbProduct
else if (!string.IsNullOrEmpty(cmbProductName.Text) && !string.IsNullOrEmpty(txtQuantity.Text))
{
Receipt obj = new Receipt() { Id = order++, ProductName = Convert.ToString(cmbProductName.SelectedItem), Quantity = Convert.ToInt32(txtQuantity.Text), Price = Convert.ToDouble(txtPrice.Text) };
total += obj.Price * obj.Quantity;
receiptBindingSource.Add(obj);
receiptBindingSource.MoveLast();
Clear();
}
txtTotal.Text = String.Format("P{0}", Convert.ToString(total));
}
这是一个新的数据。但如果单击new,我仍然无法刷新或重置receiptBindingSource中的数据。总量仍在继续计算
private void New() {
cmbProductName.Text = string.Empty;
txtPrice.Text = string.Empty;
txtQuantity.Text = string.Empty;
txtCustomerName.Text = string.Empty;
txtCustomerNumber.Text = string.Empty;
txtTotal.Text = string.Empty;
txtCash.Text = string.Empty;
receiptBindingSource.Clear();
}
任何人都可以帮助我重置、刷新receiptBindingSource,因为我无法添加新数据。我需要停止调试,以便添加新的。伙计们,请帮帮我。问题出在这行:
total += obj.Price * obj.Quantity;
您没有在任何地方重置
total
的值。在为重置编写的方法中,将total的值设置为零:total=0;非常感谢你,伙计!这对我来说很管用:D谢谢,谢谢!