thanks Rong-Chun Zhang
but i could not get it working let me provide u my full code
//form save button
private void btnSave_Click(object sender, EventArgs e)
{
try
{
this.Validate();
this.dONARCODEBindingSource.EndEdit();
result = MessageBox.Show("Do you want to Save Records", "EMUGAS
ave Confirm,Question",MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
this.dONARCODETableAdapter.Update(this.dsDonartab.DONARCODE);
MessageBox.Show("The records are applied and saved.", "EMUGAS:Record Saved,Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
return;
}
}
catch (ConstraintException ex)
{
MessageBox.Show(ex.Message.ToString());
}
//tool bar save button
private void toolbtnSave_Click(object sender, EventArgs e)
{
this.Validate();
if (!iserror)
this.btnSave_Click(null, null);
}
//data error handling
private void dgvDonar_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
this.iserror = true;
if (e.Context == DataGridViewDataErrorContexts.Commit)
{
if ((e.Exception) is ConstraintException)
{
this.dgvDonar.Rows[e.RowIndex].ErrorText = " Cannot contain duplicate value";
MessageBox.Show("primary key violation"); //data error messagebox
e.Cancel = true;
}
if ((e.Exception) is NoNullAllowedException)
{
this.dgvDonar.Rows[e.RowIndex].ErrorText = " All the fields are requierd";
MessageBox.Show("Null value cannot be saved"); //data error messagebox
e.Cancel = true;
}
}
}
Now here my toolbtnSave works fine . Whenever error occurs it raise the dataerror messagebox and messagebox.ok click it returns to datagridview and show dataerror text for input correction. My form closing event also works similary. But my problem with btnSave button it shows dataerror messagebox and when I click messagebox.ok it goes to not responding phase(app simplyhangs do not show any error).
Two buttons areshowing twodifferent nature again eventhough calling same method what might be wrong..