计算DataGridView列的和

来源:互联网 发布:文件夹批量重命名软件 编辑:程序博客网 时间:2024/05/17 06:18
ColumIndex 列index

 

 public static Decimal DGCellSumToDecimal(DataGridView DataGD, int ColumIndex)        {            decimal totalprice = 0.0m;            Decimal Dtotal = 0;            if (DataGD.Rows.Count > 0)            {                for (int i = 0; i < DataGD.Rows.Count - 1; i++)                {                    totalprice += Convert.ToDecimal(DataGD.Rows[i].Cells[ColumIndex].Value.ToString());                }                Dtotal = totalprice;            }            return Dtotal;        }


调用:如计算dataGridView1第四列的值

decimal   conut =DGCellSumToDecimal(dataGridView1, 3)

原创粉丝点击