Sub Call to form closing event

sullyman

Active member
Joined
Nov 11, 2009
Messages
37
Programming Experience
Beginner
Hi Folks,

Going around in circles here. I have an Exit button (Barbuttonitem6) on my form and would like the FormClosing event to handle this. The code works fine for the FormClosing event but when i try to call the Formclosing event from Barbuttonitem6, it does not work (The form does not close if i choose Yes to save or No)


Any help appreciated.


VB.NET:
Public Sub BarButtonItem6_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem6.ItemClick
        
Call EmployeeData_FormClosing(sender, Nothing)

End Sub

VB.NET:
Public Sub EmployeeData_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        
Select Case XtraMessageBox.Show("Do you wish to save before closing?", "Application Exit", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)

Case DialogResult.Yes

                'save code here
                              Me.D_PREVEMPEDHistoryTableAdapter.Update(Me.DsDPrevEmpEdHistory.D_PREVEMPEDHistory)

                    XtraMessageBox.Show("All records have now been saved successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2)
                End If

Case Windows.Forms.DialogResult.No

                'no code needed unless you want to do other 
                'things before closing the app instead of 
                'saving a file since we were already in the 
                'process of exiting the program

Case DialogResult.Cancel

                If e IsNot Nothing Then
                    e.Cancel = True
                End If
        End Select

    End Sub
 
You don't call event handlers, they call you in response to a related event being raised. If you close the form, that event will be raised, and your event handler is called. Use the Close instance method to close the form, eg Me.Close or EmployeeData.Close.
 
Thanks John.. That works great... Someday i'll get the hang of this :)

You don't call event handlers, they call you in response to a related event being raised. If you close the form, that event will be raised, and your event handler is called. Use the Close instance method to close the form, eg Me.Close or EmployeeData.Close.
 
Back
Top