My below code should ask the user before closing the form, if no then exit the application itself.
private void DataEntry_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
String msg = "Confirm Save?";
String caption = "Save Record";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
MessageBoxIcon ico = MessageBoxIcon.Question;
DialogResult result;
result = MessageBox.Show(this, msg, caption, buttons, ico);
if (result == DialogResult.Yes)
{
this.Validate();
this.tool_ManagementBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.pINQCDataSet);
MessageBox.Show("The Record saved Successfully", "Save_Update",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
Application.Exit();
}
}
catch (Exception ex)
{
MessageBox.Show("Saving Failed:" + ex.Message.ToString(), "Save",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
But I am getting message box appeared twice even after clicking no , then the below error appears , please guide me how to solve this problem.
@karenpayneoregon :pls help me.
