Strange Form behavior

M

Matt

Hi all.. Something strange with something that should be simple.

Have a form with a button that calls another form (showdialog)
--

10 Dim f As New frmTrainRecMaint(frmTrainRecMaint.enmFormAction.AddNew)
20 f.ShowDialog()
30 If f.dialogResult = DialogResult.OK Then
40 SetupDG()
50 End If

--


frmForm has a cancel button, under the click event I have:

--
5 Private Sub btnCancel_Click (...)
10 If ChangesMade = True Then
20 If MessageBox.Show("Changes made, cancel?", "Verify Cancel",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
30 Me.DialogResult = DialogResult.Cancel
40 Me.Dispose()
50 End If
60 End If
70 End Sub
--

tracking it, everything works great, but when it gets to the end of the
click event, 70,
the run jumps back to the parent form and continues with 30.

frmForm dissapears. It never runs the me.dispose, so where'd it go!?!?

Help! Thanks,

Matt
 
N

Noozer

5 Private Sub btnCancel_Click (...)
10 If ChangesMade = True Then
20 If MessageBox.Show("Changes made, cancel?", "Verify Cancel",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
30 Me.DialogResult = DialogResult.Cancel
40 Me.Dispose()
50 End If
60 End If
70 End Sub

At line 5 Me.DialogResult is already DialogResult.Cancel, since the user
clicked the cancel button. Nowhere in this Sub do you change the result to
anything else, so it should ALWAYS be cancel.
 
M

Matt

Thanks! Changed the dr to none and my code controls the canceling now.

Thanks Again,

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top