【问题标题】:grid view cells automatically adding 0 at the foot of subtotal grid view网格视图单元格在小计网格视图的底部自动添加 0
【发布时间】:2013-01-23 18:15:15
【问题描述】:

为什么网格视图单元格会在小计网格视图的底部自动添加 0?

        int qty = 0;
        int amount = 0;
        int rowtotal = 0;
        int subtotal = 0;
        int total = 0;

        foreach (DataGridViewRow row in itemgridview.Rows)
        {
            qty = Convert.ToInt32(row.Cells[1].Value); 
            amount = Convert.ToInt32(row.Cells[2].Value); 
            rowtotal = qty * amount;
            row.Cells[3].Value = rowtotal;
            subtotal += rowtotal;

        }

        total = subtotal;
        txtordertotal.Text = total.ToString();

【问题讨论】:

  • 他的意思是 GridView 中的“新行”,即您要输入数据以添加行的部分,已经将其小计预填充为 0。
  • 它还在计算最后一行的总计,因为它没有任何 qty 和金额的值,它节省了 0,因为小计默认为 0。

标签: c# .net vb.net datagridview


【解决方案1】:

创建AllowUsersToAddRow = false,然后重试。此属性将删除多余的行。

【讨论】:

  • 嘿伙计,它的工作原理就像魅力一样,当我尝试将所有这些数据添加到数据库中时,它会添加任何重复项吗?
  • 不,它不会添加任何重复项,如果它适用于您将其标记为已回答并投票 :-) 谢谢
猜你喜欢
  • 1970-01-01
  • 2020-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多