|
-
Apr 3rd, 2011, 03:25 PM
#1
Thread Starter
Junior Member
Checking for changes before closing (HasChanges)
I'm having trouble using the HasChanges method.
I'm trying to get a message box to show if a user hits the edit button, makes a change, then hits the close button without hitting the save button first. From what I understand, the HasChanges(DataRowState.Modified) statement should work.
In reality, when I hit the edit button, make a change to a field (zip for example), then hit the close, it just closes without showing the messagebox.
Here's my code so far...
Code:
Private Sub CustomerForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles Me.FormClosing
'check for unsaved changes
Dim AnswerDialogResult As DialogResult
If aCarsDataSet.HasChanges(DataRowState.Modified) Then
'query user to save changes
AnswerDialogResult = MessageBox.Show("Do you want to save the changes?", "Unsaved Changes", _
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button2)
Select Case DialogResult.Yes
Case Windows.Forms.DialogResult.Yes
'save dataset
aCustomerBindingSource.EndEdit()
aCustomerTableAdapter.Update(aCarsDataSet)
'cancel closing
e.Cancel = True
End Select
End If
AnInstance = Nothing
End Sub
Not really sure why this doesn't ever get triggered. Slowly running out of ideas.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|