المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : cancelling the dataGridview RowValidating event is not returning me to the grid so i can edit the empty cell



C# Programming
07-26-2012, 04:30 PM
Iam trying to cancel the RowValidating event in a dataGridview but but after cancelling the event, am not returned to the grid so i can edit the row that was being validated.

In my Grid, if the isCreditSale column value is True and CustomerID column value is Empty, i want to cancel the event, tell the user what the error is, and return the user to the grid so they can edit the row cell values.

Unfortunately, when the messagebox pops up, it never goes away even if you click ok 100 times not until you just terminate the process.

This is the sample code,

private void dataGridView1_RowValidating(object sender, DataGridViewCellCancelEventArgs e) { if (dataGridView1.Rows[e.RowIndex].IsNewRow) { return; } string customer = dataGridView1.Rows[e.RowIndex].Cells["customerID"].FormattedValue.ToString(); decimal paid; decimal.TryParse(dataGridView1.Rows[e.RowIndex].Cells["amountPaid"].FormattedValue.ToString(), out paid); bool isCredit; bool.TryParse(dataGridView1.Rows[e.RowIndex].Cells["isCreditSale"].FormattedValue.ToString(), out isCredit); if (isCredit == true && string.IsNullOrEmpty(customer)) { MessageBox.Show("Please enter a customer name for this credit sale", "", MessageBoxButtons.OK, MessageBoxIcon.Error); e.Cancel = true; } }