当我更改组合框的成员时,我想上下更改数字的文本(或值)。我喜欢这样:
private void cbProductName_ValueMemberChanged(object sender, EventArgs e)
{
if ((int)cbProductName.SelectedValue != 0)
{
using (UnitOfWork db = new UnitOfWork())
{
txtSalesPrice.ResetText();
int id = Convert.ToInt32(cbProductName.SelectedValue); ;
float salesPrice = db.FactorRepository.GetSalesPriceById(id);
txtSalesPrice.Value = (decimal)(salesPrice);
float discountPrice = float.Parse(txtDiscountPrice.Value.ToString());
float finalPrice = FinalPrice.GetFinalPrice(salesPrice, discountPrice);
txtFinalPrice.Value = (decimal)finalPrice;
txtSalesPrice.Value = (decimal)salesPrice;
}
txtSalePrice和txtFinalPrice是数字
但这不起作用。我要去哪里错了?
答案 0 :(得分:0)
这是Microsoft的一个示例,与您要执行的操作类似。
// Check box to toggle decimal places to be displayed.
private void checkBox1_Click(Object sender, EventArgs e)
{
/* If DecimalPlaces is greater than 0, set them to 0 and round the
current Value; otherwise, set DecimalPlaces to 2 and change the
Increment to 0.25. */
if (numericUpDown1.DecimalPlaces > 0)
{
numericUpDown1.DecimalPlaces = 0;
numericUpDown1.Value = Decimal.Round(numericUpDown1.Value, 0);
}
else
{
numericUpDown1.DecimalPlaces = 2;
numericUpDown1.Increment = 0.25M;
}
}
我建议您查看更改“增量”是否对您的问题有所帮助。