after validating if all fields are available in a datagridview row, using RowValidating event; if the user accidently clicks on a new row, then the validations are triggered and not letting form to close.
Below is the code
private void dgv1_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
if (dgv1.CurrentRow != null)
{
DataGridViewRow dgvRow = dgv1.CurrentRow;
if (dgvRow.Cells["txtEmpName"].Value == DBNull.Value)
{
MessageBox.Show("Employee Name cannot be empty");
e.Cancel = true;
}
}
}
the user enters one row successfully and clicks on next row. then row validation triggers and not letting form to close.

Dinesh GabhaneRank #265 · 9.5K reputationPosted Oct 12, 2019, 9:14 PM EDT
anna john33 reputationPosted Oct 15, 2019, 8:22 AM EDT
anna john33 reputationPosted Oct 16, 2019, 8:37 AM EDT