创建分类汇总的总计
本文关键字:分类汇总 创建 | 更新日期: 2023-09-27 18:37:23
嗨,我正在尝试创建这个程序,其中 txtbox1 将根据用户的输入相乘并自动显示与其他 txtbox 相同的小数点总数,但我很难将每个结果的所有小计汇总到总 txtbox 总数
这是我在每个小计中的代码
private void txtbox11_TextChanged_1(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtbox12.Text))
txtTotal11.Text =
(Convert.ToInt32(txtbox11.Text)*Convert.ToDecimal(112.61)).ToString();
}
private void txtbox12_TextChanged_1(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtbox12.Text))
txtTotal12.Text =
(Convert.ToInt32(txtbox12.Text) * Convert.ToDecimal(32.10)).ToString();
}
如何自动获取 txtTotal11 和 txtTotal12 的总和以显示在 txtTotal13 上?或者我是否应该在每个 txtTotal# 上放置一个像"textChanged"这样的事件?谢谢大家,我真的很头疼。
它将
是这样的:
private void txtboxSubTotal1_TextChanged_1(object sender, EventArgs e)
{
CalcGrandTotal();
}
private void txtboxSubTotal2_TextChanged_1(object sender, EventArgs e)
{
CalcGrandTotal();
}
private void CalcGrandTotal()
{
decimal grandTotal = 0;
decimal parseValue= 0;
if (!string.IsNullOrEmpty(txtboxSubTotal1.Text) && decimal.TryParse(txtboxSubTotal1.Text, parseValue))
grandTotal += parseValue;
if (!string.IsNullOrEmpty(txtboxSubTotal2.Text) && decimal.TryParse(txtboxSubTotal2.Text, parseValue))
grandTotal += parseValue;
txtboxGrandTotal.Text = grandTotal.ToString();
}
试试这个:(在每个 TextChanged 事件中)
decimal total13;
private void txtbox11_TextChanged_1(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtbox12.Text))
var thisTotal = (Convert.ToInt32(txtbox11.Text)*Convert.ToDecimal(112.61)).ToString();
txtTotal11.Text = thisTotal
total13 += thisTotal
txtTotal13.Text = thisTotal.ToString();
}