将datagrideview中的多列求和并添加页脚 [英] Sum multi columns in datagrideview and add in footer

查看:151
本文介绍了将datagrideview中的多列求和并添加页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些代码与我一起对datagrideview中的一列求和,但我想对datagrideview中的多列求和

these code work with me to sum one column in datagrideview but i want to sum multi columns in datagrideview

decimal sum1 = 0, sum2 = 0;
            for (int i = 0; i < dgw.RowCount; i++)
            {
                // we only sum the first and third column as an example
                sum1 += Convert.ToDecimal(dgw.Rows[i].Cells[4].Value);
                sum2 += Convert.ToDecimal(dgw.Rows[i].Cells[5].Value);
            }
            // add the total row
            string[] totalrow = new string[] { sum1.ToString(), "", sum2.ToString() };
            dgw.Rows.Add(totalrow);
            // add a rowheadertitle
            dgw.RowHeadersWidth = 60;
            dgw.Rows[dgw.RowCount - 1].HeaderCell.Value = "Total"; 



我尝试过的事情:

这些代码与我一起对datagrideview中的一列求和,但是我想对datagrideview中的多列求和.



What I have tried:

these code work with me to sum one column in datagrideview but i want to sum multi columns in datagrideview

推荐答案

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