I have a function for a dialog which returns the dialog result back.
However, the value of the dialogresult changes from ok to cancel after the value is returned. How can i fix this?

this is the part where the dialog is called and the value from the dialog is returned.

Private Sub btnLogin_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnLogin.ItemClick
        Dim loginDialog As New frmLogin
        Dim result As DialogResult = Nothing
        result = loginDialog.ShowDialog()
        If result = Windows.Forms.DialogResult.OK Then
            If My.Settings.User = "administrator" Then My.Settings.AccessCode = "admin"
            My.Settings.AccessCode = ShippingClass.funcGetAcessCode(My.Settings.User)
        End If
          End Sub

This is the function that returns the dialog result.

Private Function OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Dim result As DialogResult

        If txtPassword.Text = Nothing Or txtUserID.Text = Nothing Then
            MessageBox.Show("Please check your user name and password", "Invalid Login")
            Exit Function
        End If

        If ShippingClass.funcAuthenticate(txtUserID.Text, txtPassword.Text) = True Then
            My.Settings.User = txtUserID.Text
            doExit = True
            result = Windows.Forms.DialogResult.OK
            Return result
            MessageBox.Show("Authentication Failed:" & vbCrLf & "The User ID and password you have entered does not match. Please check your login info and try again.", "Authentication Failure")
        End If
    End Function

btnLogin_ItemClick opens login dialog which returns a value as result back to btnLogin_ItemClick using the function OK_Click.
While debugging, the returning value after sucessful authentication should and is dialogresult.ok until it is passed back to btnLogin where the result value changes from 'Ok' to 'Cancel'

Member Avatar

Looks like me.close may be giving you a problem.

I would change:

If ShippingClass...... then
    My.Settings.User = txtUserID.Text
    Me.DialogResult = Windows.Forms.DialogResult.OK
End if

And your Private Function OK_Click should be Private Sub OK_Click . When handling an event it doesn't return a value.

commented: willingness to help +4