1. I got this code below to handle my save before exit. But whenver I click the red (x) on form, but it did not do anything. Whether I click Yes/No/Cancel, it will only close the program. I don’t see what I do wrong that make it behavior like this. Please guide me to right direction.
2. Is there a way to make the messagebox show only when user make change. Like if they click savebtn then click close (x) the message will not show up, but the message going to show up if user make change and did not click savebtn before close.
2. Is there a way to make the messagebox show only when user make change. Like if they click savebtn then click close (x) the message will not show up, but the message going to show up if user make change and did not click savebtn before close.
Private Sub Detail_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim response As DialogResult
MessageBox.Show("Do you want to save any changes before closing this window?", "DTL", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3)
If response = Windows.Forms.DialogResult.Cancel Then
Me.TextBox1.Focus()
ElseIf response = Windows.Forms.DialogResult.No Then
Me.Close()
ElseIf response = Windows.Forms.DialogResult.Yes Then
Try
Me.Validate()
Me.DTLBindingSource.EndEdit()
Me. DTLTableAdapter.Update(Me.PtmnDataSet.DTL)
Me.Close()
Catch ex As Exception
MessageBox.Show("Unable to Save! " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub