private void goodsDataDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            //计算金额
            //MessageBox.Show(goodsDataDataGridView.Rows[goodsDataDataGridView.CurrentCellAddress.Y].Cells["单价DataGridViewTextBoxColumn"].Value.ToString());
            if ((goodsDataDataGridView.Rows[e.RowIndex].Cells["单价DataGridViewTextBoxColumn"] == goodsDataDataGridView.CurrentCell)||(goodsDataDataGridView.Rows[e.RowIndex].Cells["数量DataGridViewTextBoxColumn"]==goodsDataDataGridView.CurrentCell))
            {
                if((goodsDataDataGridView.Rows[e.RowIndex].Cells["单价DataGridViewTextBoxColumn"]!=null)&&(goodsDataDataGridView.Rows[e.RowIndex].Cells["数量DataGridViewTextBoxColumn"]!=null))//为什么这里当单元格为空时,程序还要执行下面的语句呢?有什么其它的办法没有?
                goodsDataDataGridView.Rows[goodsDataDataGridView.CurrentCellAddress.Y].Cells["金额DataGridViewTextBoxColumn"].Value = (decimal)goodsDataDataGridView.Rows[goodsDataDataGridView.CurrentCellAddress.Y].Cells["单价DataGridViewTextBoxColumn"].Value * (decimal)goodsDataDataGridView.Rows[goodsDataDataGridView.CurrentCellAddress.Y].Cells["数量DataGridViewTextBoxColumn"].Value;
                //goodsDataBindingNavigatorSaveItem_Click(this, e);
            }
        }        private void goodsDataDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {//怎样得到出错列的列名,我只列名
            MessageBox.Show(e.Exception.Message.ToString() + " 列不允许为空!", "数据操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
          
        }

解决方案 »

  1.   

    goodsDataDataGridView.Rows[e.RowIndex].Cells["数量DataGridViewTextBoxColumn"]!=null 和goodsDataDataGridView.Rows[e.RowIndex].Cells["数量DataGridViewTextBoxColumn"]!="" 是不一样的.你把后一句加上看看
      

  2.   

    自己解决,自己太菜,所以才....
    goodsDataDataGridView.Rows[e.RowIndex].Cells["单价DataGridViewTextBoxColumn"].Value.ToString() != "" 
    MessageBox.Show(e.Exception.Message.ToString() , "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);