how I can show the sum of in a datagridview column

2019-01-06 17:13发布

I need to show the sum of the count column from this datagridview, but I don't know how I can get to the data in the datagridview.

When I click on the button, I want to show 94 in label1.

How can this be done?

alt text

8条回答
叼着烟拽天下
2楼-- · 2019-01-06 17:56

Add the total row to your data collection that will be bound to the grid.

查看更多
\"骚年 ilove
3楼-- · 2019-01-06 17:59
//declare the total variable
int total = 0;
//loop through the datagrid and sum the column 
for(int i=0;i<datagridview1.Rows.Count;i++)
{
    total +=int.Parse(datagridview1.Rows[i].Cells["CELL NAME OR INDEX"].Value.ToString());

}
string tota
查看更多
登录 后发表回答