繁体   English   中英

从Datagridview到标签或最后一行

[英]From Datagridview to lable or last row

我正在尝试从datagridview获取总和到datagridview的标签或最后一行,请帮助我,这是我的代码

public void total()
    {
            foreach (DataGridViewRow item in tbl_Purchase.Rows)
            {
                int n = item.Index;
                int tPrice=0;
                int tQuantity=0;
                int tAmount=0
                tPrice += (int.Parse(tbl_Purchase.Rows[n].Cells[3].Value.ToString()));
                tQuantity += (int.Parse(tbl_Purchase.Rows[n].Cells[4].Value.ToString()));
                tAmount += (int.Parse(tbl_Purchase.Rows[n].Cells[5].Value.ToString()));
                l_Price.Text = (Convert.ToString(tPrice));
                l_Quantity.Text = (Convert.ToString(tQuantity));
                l_Amount.Text = (Convert.ToString(tAmount));

            }

    }
public void total()
    {
        var tPrice=0;
        var tQuantity=0;
        var tAmount=0
        foreach (DataGridViewRow item in tbl_Purchase.Rows)
        {
            tPrice += (int.Parse(tbl_Purchase.Rows[item.Index].Cells[3].Value.ToString()));
            tQuantity += (int.Parse(tbl_Purchase.Rows[item.Index].Cells[4].Value.ToString()));
            tAmount += (int.Parse(tbl_Purchase.Rows[item.Index].Cells[5].Value.ToString()));    
        }
        l_Price.Text = (Convert.ToString(tPrice));
        l_Quantity.Text = (Convert.ToString(tQuantity));
        l_Amount.Text = (Convert.ToString(tAmount));
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM