Strange messagebox/Form action

M

Matt Gabbard

Greetins all,

I have a problem that has me beating my head against the desk..

A simple form with a buttong, creates a sime form via click:

---
If lv1.SelectedItems.Count > 0 Then
Dim f As New frmAddEditEmp(CInt(lv1.SelectedItems(0).SubItems(0).Text))
f.ShowDialog()
End If
---

On frmAddEditEmp, all it has are a couple of text boxes, a save button and a
cancel button...
If a text box gets changed I'm setting a boolean var to 'true'

On the cancel button.click I have this code:
---
If _changed = True Then
If MessageBox.Show("Changes Made. Are you Sure you want to cancel?",
"Confirm Cancel", & _
MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Me.Close()
End If
End If
---

No matter what I try, if I click 'No' on the message, the form disappears
and it takes me back to the parent... It should just exit the sub and keep
the form open.

I tried setting the form's cancel button property to use this button as well
as not using the cancel property, both have the same result.

I am woring on this in VS 2005 now, but tried it in 2003 with the same
results as well...

Thanks!

Matt
 
G

Greg Burns

This is the code I use.

If MessageBox.Show("Changes Made. Are you Sure you want to cancel?",
"Confirm Cancel", _
MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then

Me.DialogResult = Windows.Forms.DialogResult.Cancel
Else
Me.DialogResult = Nothing
End If

I don't bother calling Me.Close. Is it correct? I dunno. :)

Greg
 

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