Good Day to everyone...
So Here is my problem.
I Have a Windows Form -Personnel form ..
After you finish entering data there is a save command button become visible.this Save Btn works properly with this Function :
My problem is the EXIT Button
If you press it i want to prompt you for saving the data or not.There is a mistake in the following Code but i do not know where it is..
I would be happy if someone would give me a guideline..thanx in advance..
So Here is my problem.
I Have a Windows Form -Personnel form ..
After you finish entering data there is a save command button become visible.this Save Btn works properly with this Function :
VB.NET:
Private Function Save() As Boolean
Dim Saved As Boolean = False
If MyDataSet.HasChanges Then
Try
Dim MyTableUpdates() As DataRow = MyDataSet.Mytable.Select("", "", DataViewRowState.Added Or DataViewRowState.ModifiedCurrent)
MyTableAdapter.Update(MyTableUpdates)
Saved = True
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End If
return saved
End Function
Private Sub ButtonSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.MyTableBindingSource.EndEdit()
If Me.Save() Then
MsgBox("Changes Saved")
End If
End Sub
My problem is the EXIT Button
If you press it i want to prompt you for saving the data or not.There is a mistake in the following Code but i do not know where it is..
VB.NET:
Private Sub ButtonExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.Save() Then
Me.Close()
Else
Dim result = MsgBox("Do you want to save before closing?", MsgBoxStyle.YesNo Or MsgBoxStyle.Exclamation)
If result = vbYes Then
Me.Save()
If result = vbNo Then
Me.Close()
End If
End If
End If
End Sub
I would be happy if someone would give me a guideline..thanx in advance..