I have a form that is linked to a database and allows a user to insert, update and delete records. I want the user to be notified of any unsaved changes when they click to go back to the main menu, and have the option whether or not to save them.
The code I have so far is below, but it doesn't recognize the changes. It just goes straight back to the main menu.
private void btnBack_Click(object sender, EventArgs e)
{
frmMenu frmMainMenu = new frmMenu();
if (dsOrders.HasChanges())
{
if (DialogResult.Yes == MessageBox.Show("There are changes that have not been saved and will be lost. Would you like to save them before leaving this form?", "Unsaved Changes", MessageBoxButtons.YesNo))
{
dsOrders.AcceptChanges();
}
else
{
frmOrders.ActiveForm.Hide();
frmMainMenu.Show();
}
}
else
{
frmOrders.ActiveForm.Hide();
frmMainMenu.Show();
}
}