//光标离开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 > 0)
    {
        for (int i = 0; i < count; i++)
        {
            double dyslstr = 0.0;
            if (this.dgpz_dataGridView.Rows[i].Cells[2].Value == null)
            {
                dyslstr = 0.0;
            }
            else
            {
                dyslstr = double.Parse(this.dgpz_dataGridView.Rows[i].Cells[2].Value.ToString());
            }
            if (!dyslstr.ToString().Trim().Equals(""))
            {
                zl = zl + dyslstr;
            }
            
        }
    }
    this.sl.Text = zl.ToString();//多个品种的总调运量加在一起传给重量 

}

 

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

 

 posted on 2016-12-14 14:02  布鲁布鲁sky  阅读(1637)  评论(0编辑  收藏  举报