我正在尝试通过处理事件在第一个(supplierDiscountPercetangeSpinEdit)SpinEdit中更改值时在另一个(supplierPriceWithDiscountSpinEdit)SpinEdit控件上设置值:
private void supplierDiscountPercetangeSpinEdit_EditValueChanging(object sender,
DevExpress.XtraEditors.Controls.ChangingEventArgs e)
{
try
{
decimal supplierPrice, supplierDiscount, supplierPriceWithDiscount;
supplierPrice = Convert.ToDecimal(supplierPriceSpinEdit.EditValue);
supplierDiscount = (decimal)e.NewValue;
supplierPriceWithDiscount = Discount.DoMath(
supplierPrice, supplierDiscount);
supplierPriceWithDiscountSpinEdit.EditValue = Convert.ToDecimal(
supplierPriceWithDiscount);
}
catch
{
throw; // Additional information: Specified cast is not valid.
}
}
当我使用Up& amp; amp; amp; amp; amp;按下控制按钮,但按下按键异常会抛出消息附加信息:指定的强制转换无效。
可能问题是行:supplierDiscount = (decimal)e.NewValue;
答案 0 :(得分:0)
无法将字符串转换为十进制必须解析
decimal supplierDiscount = decimal.Parse("1.00");
答案 1 :(得分:0)
您已在前一行回答了您的问题:
supplierPrice = Convert.ToDecimal(supplierPriceSpinEdit.EditValue);
您在处理程序supplierDiscountPercetangeSpinEdit_EditValueChanging
中,我只能假设处理EditValue
对象的SpinEdit
属性更改。因此e.NewValue
反映了该财产价值。以上是处理相同的属性,所以你应该以同样的方式处理这个:
supplierDiscount = Convert.ToDecimal(e.NewValue);