Problem with DialogResult property

F

Frank Maxey

I am fairly new to VB.Net and am having a curious problem.

I have an entry dialog form called from a main form. The calling form
needs to check the
DialogResult field for an OK response.

In my button service in the dialog form, I have:

Private Sub btnSave_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnSave.Click
 
W

William Ryan eMVP

Frank:

Have you set the AcceptButton and CancelButton and/or are you setting the
dialogresult within the form?
 
J

Juan Romero

I have had this problem before and the only thing I can tell you (since I
never figured it out) is make your own form property. That works.
 
F

Frank Maxey

I figured to add a property as a last resort, but I would have liked
to use the standard properties. I set the Cancel and Accept buttons,
just to be sure, but it didn't do any good.

It was at least reassuring to know somebody else had the same problem.
Thanks

Frank Maxey
(e-mail address removed)
(Remove 'KeinSpam' to reply to my e-mail address)
 
J

Jay B. Harlow [MVP - Outlook]

Frank,
Normally what I do is what William Ryan was asking about.

On the DialogForm form:
Form.AcceptButton = buttonSave
Form.CancelButton = buttonCancel

On the buttonSave button:
Button.DialogResult = DialogResult.Ok

On the buttonCancel button:
Button.DialogResult = DialogResult.Cancel


The Form will automatically handle setting Form.DialogResult & calling
Form.Hide when you click either button, or press the Enter or Cancel key.

Alternatively, if you set Form.DialogResult within your event handler, Hide
is automatically called for you.

Is this with VS.NET 2002 or VS.NET 2003? I could not replicate you problem
with VS.NET 2003.

Hope this helps
Jay
 
F

Frank Maxey

I have the 2002 version.

I had already tried setting the buttons that you outline below, with
no success. I found it was easier and more straightforward to create
another property for the form.

According to the Microsoft's documentation (I should know better by
now) it should be sufficient just to use:

Form.DialogResult = DialogResult.OK
Form.Hide()

I think I'll just stick with writing my own properties explicitly. At
least I can be certain how they work.

Thanks for the reply.

Frank Maxey
(e-mail address removed)
(Remove 'KeinSpam' to reply to my e-mail address)
 
J

Jay B. Harlow [MVP - Outlook]

Frank,
According to the Microsoft's documentation (I should know better by
now) it should be sufficient just to use:

Form.DialogResult = DialogResult.OK
Form.Hide()

What documentation??? Remember documentation can be wrong or misleading...
You actually do not need the Form.Hide!

All you need in VS.NET 2002 & VS.NET 2003 is:

Private Sub btnSave_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnSave.Click
Me.DialogResult = DialogResult.OK
End Sub

However I prefer setting the Button.DialogResult & Form.AcceptButton, then I
do not need the event handlers. Which also works in both VS.NET 2002 &
VS.NET 2003.

Can you post (if its small) or email me a complete sample of what you are
doing, I am not able to recreate what you describe, given the information
you posted.

IMPORTANT: Within in your EntryForm are you setting DialogResult any place
other then the button's click event handlers? Such as the Closed event?

The only way I was able to recreate what you are seeing is by adding the
following to my form:

Private Sub AboutDialog_Closed(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Closed
Me.DialogResult = DialogResult.Cancel
End Sub

Which definitely is not needed, as the form automatically returns Cancel if
you click the Close button!

Hope this helps
Jay

Frank Maxey said:
I have the 2002 version.

I had already tried setting the buttons that you outline below, with
no success. I found it was easier and more straightforward to create
another property for the form.

According to the Microsoft's documentation (I should know better by
now) it should be sufficient just to use:

Form.DialogResult = DialogResult.OK
Form.Hide()

I think I'll just stick with writing my own properties explicitly. At
least I can be certain how they work.

Thanks for the reply.

Frank Maxey
(e-mail address removed)
(Remove 'KeinSpam' to reply to my e-mail address)

"Jay B. Harlow [MVP - Outlook]" <[email protected]> wrote in message
Frank,
Normally what I do is what William Ryan was asking about.

On the DialogForm form:
Form.AcceptButton = buttonSave
Form.CancelButton = buttonCancel

On the buttonSave button:
Button.DialogResult = DialogResult.Ok

On the buttonCancel button:
Button.DialogResult = DialogResult.Cancel


The Form will automatically handle setting Form.DialogResult & calling
Form.Hide when you click either button, or press the Enter or Cancel key.

Alternatively, if you set Form.DialogResult within your event handler, Hide
is automatically called for you.

Is this with VS.NET 2002 or VS.NET 2003? I could not replicate you problem
with VS.NET 2003.

Hope this helps
Jay




(since
I
 

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