我想要做的就是在一个列表框 进入项目,其价格终于攻克了项目的总价格有什么毛病我在C#windowsform代码
这是我至今
代码private void btnItems_Click(object sender, EventArgs e)
{
Market super = new Market();
// double total = 0;
super._items = txtItems.Text;
txtItems.Text = string.Empty;
super._price = Convert.ToDouble(txtPrice.Text);
txtPrice.Text = string.Empty;
lstShow.Items.Add(super._items + " $ " + super._price);
}
private void btnPrice_Click(object sender, EventArgs e)
{
Market super = new Market();
lstShow.Items.Add("---------------------------------");
decimal suma = 0;
foreach (var item in lstShow.Items)
{
decimal d = Convert.ToDecimal(item); //OJO solo para Winforms y si se metieron los items con un formato compatible con Decimal
suma += d;
}
txtTotal.Text=(suma.ToString());
}
,但显示这个例外:(
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
其他信息:
Input string was not in a correct format
异常的堆栈跟踪添加到该问题的文本下面的代码。 – 2014-08-30 23:26:51