DatagridView的CellLeave光标离开响应事件,实现某列数字自动求和

时间:2020-12-25 05:03:33

DatagridView的CellLeave光标离开响应事件,实现某列数字自动求和

//光标离开DatagridView,循环获取DatagridView的每一行的第3列的值,相加传给重量
private void dgpz_dataGridView_CellLeave(object sender, DataGridViewCellEventArgs e)
{
this.dgpz_dataGridView.EndEdit();//光标离开,完成修改 double zl = 0.0;
int count = dgpz_dataGridView.Rows.Count;
if (count > )
{
for (int i = ; i < count; i++)
{
double dyslstr = 0.0;
if (this.dgpz_dataGridView.Rows[i].Cells[].Value == null)
{
dyslstr = 0.0;
}
else
{
dyslstr = double.Parse(this.dgpz_dataGridView.Rows[i].Cells[].Value.ToString());
}
if (!dyslstr.ToString().Trim().Equals(""))
{
zl = zl + dyslstr;
} }
}
this.sl.Text = zl.ToString();//多个品种的总调运量加在一起传给重量 }

光标离开DatagridView后,实现效果:

DatagridView的CellLeave光标离开响应事件,实现某列数字自动求和