DataGridView的问题 [英] A problem with DataGridView

查看:56
本文介绍了DataGridView的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();`



请帮我提前谢谢网格查看单元格自动在脚下添加0我的c#中的小计网格视图?这是我附上图片的代码片段,请随时查看:) http://s13.postimage。 org / 95vh13rfr / error.jpg [ ^ ]

推荐答案

int i = 0;
foreach (DataGridViewRow dgvr in itemgridview.Rows)
{
    if (dgvr.IsNewRow)
    {
        // do nothing
    }
    else
    {
        int j = 0;
        if (int.TryParse(dgvr.Cells[3].Value + "", out j))
        {
            i += j;
        }
        else
        {
            MessageBox.Show("wrong value at row " + (dgvr.Index + 1));
            return;
        }
    }
}
txtordertotal.Text = i.ToString();


这篇关于DataGridView的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆