private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { if (e.ColumnIndex == 2) { if (e.RowIndex >= T.count) { return; } int n = e.RowIndex; String s = e.FormattedValue.ToString(); if (String.IsNullOrEmpty(s) || s == "null") { MessageBox.Show("数值不能为空"); dataGridView1.Rows[n].ErrorText = "数值不能为空"; e.Cancel = true; return; } else if (!T.Update(s, n)) { dataGridView1.Rows[n].ErrorText = MyDataTable.Error; MessageBox.Show(MyDataTable.Error); e.Cancel = true; return; } for (int i = 0; i < T.count; i++) { if (T.Buf[i].exist) { dataGridView1.Rows[i].Cells[1].Value = T.Buf[i].letter + " = " + T.Buf[i].value.ToString(); } else { dataGridView1.Rows[i].Cells[1].Value = T.Buf[i].letter + " = null"; } } } }