private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) 
        { 
            double c = 0.0; 
            dataGridView1.Rows[e.RowIndex].ErrorText = string.Empty; 
            if(dataGridView1.Columns[e.ColumnIndex].DataPropertyName == "") 
            { 
                if(!double.TryParse(e.FormattedValue.ToString(),out c) || c<0.0) 
                { 
                    dataGridView1.Rows[e.RowIndex].ErrorText = "数量输入有误!"; 
                    e.Cancel = true; 
                } 
            } 
        } 
要编辑结束后才能执行事件