By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,341 Members | 1,396 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,341 IT Pros & Developers. It's quick & easy.

Problem with DialogResult property

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Frank:

Have you set the AcceptButton and CancelButton and/or are you setting the
dialogresult within the form?
"Frank Maxey" <fd*****@yahoo.com> wrote in message
news:12**************************@posting.google.c om...
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
.
.
.
Me.DialogResult = DialogResult.OK
Me.Hide()
End Sub
The call to the form is:

Dim frm As EntryForm

frm = New EntryForm()

Dim res as DialogResult = frm.ShowDialog()

If res = DialogResult.OK Then
< Service OK response>
End If

frm = Nothing
The Save button click service is definitely called but the result in
the
calling form always shows DialogResult.Cancel. If I step through the
code, the DialogResult is set to OK up to and including the Hide
method
call. However, the result is always Cancel.

I've tried changing the code to:

frm.ShowDialog()
Dim res as DialogResult = frm.DialogResult

with no success

I'm missing something obvious here, but I don't know what.

TIA

Frank Maxey
fd*************@yahoo.com
(Remove 'KeinSpam' to reply to my e-mail address)

Nov 20 '05 #2

P: n/a
Frank, I just saw you did, my oversight.
"Frank Maxey" <fd*****@yahoo.com> wrote in message
news:12**************************@posting.google.c om...
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
.
.
.
Me.DialogResult = DialogResult.OK
Me.Hide()
End Sub
The call to the form is:

Dim frm As EntryForm

frm = New EntryForm()

Dim res as DialogResult = frm.ShowDialog()

If res = DialogResult.OK Then
< Service OK response>
End If

frm = Nothing
The Save button click service is definitely called but the result in
the
calling form always shows DialogResult.Cancel. If I step through the
code, the DialogResult is set to OK up to and including the Hide
method
call. However, the result is always Cancel.

I've tried changing the code to:

frm.ShowDialog()
Dim res as DialogResult = frm.DialogResult

with no success

I'm missing something obvious here, but I don't know what.

TIA

Frank Maxey
fd*************@yahoo.com
(Remove 'KeinSpam' to reply to my e-mail address)

Nov 20 '05 #3

P: n/a
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.

"Frank Maxey" <fd*****@yahoo.com> wrote in message
news:12**************************@posting.google.c om...
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
.
.
.
Me.DialogResult = DialogResult.OK
Me.Hide()
End Sub
The call to the form is:

Dim frm As EntryForm

frm = New EntryForm()

Dim res as DialogResult = frm.ShowDialog()

If res = DialogResult.OK Then
< Service OK response>
End If

frm = Nothing
The Save button click service is definitely called but the result in
the
calling form always shows DialogResult.Cancel. If I step through the
code, the DialogResult is set to OK up to and including the Hide
method
call. However, the result is always Cancel.

I've tried changing the code to:

frm.ShowDialog()
Dim res as DialogResult = frm.DialogResult

with no success

I'm missing something obvious here, but I don't know what.

TIA

Frank Maxey
fd*************@yahoo.com
(Remove 'KeinSpam' to reply to my e-mail address)

Nov 20 '05 #4

P: n/a
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
fd*************@yahoo.com
(Remove 'KeinSpam' to reply to my e-mail address)

"Juan Romero" <ju*********@bowne.com> wrote in message news:<eu**************@TK2MSFTNGP09.phx.gbl>...
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.

"Frank Maxey" <fd*****@yahoo.com> wrote in message
news:12**************************@posting.google.c om...
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
.
.
.
Me.DialogResult = DialogResult.OK
Me.Hide()
End Sub
The call to the form is:

Dim frm As EntryForm

frm = New EntryForm()

Dim res as DialogResult = frm.ShowDialog()

If res = DialogResult.OK Then
< Service OK response>
End If

frm = Nothing
The Save button click service is definitely called but the result in
the
calling form always shows DialogResult.Cancel. If I step through the
code, the DialogResult is set to OK up to and including the Hide
method
call. However, the result is always Cancel.

I've tried changing the code to:

frm.ShowDialog()
Dim res as DialogResult = frm.DialogResult

with no success

I'm missing something obvious here, but I don't know what.

TIA

Frank Maxey
fd*************@yahoo.com
(Remove 'KeinSpam' to reply to my e-mail address)

Nov 20 '05 #5

P: n/a
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

"Frank Maxey" <fd*****@yahoo.com> wrote in message
news:12*************************@posting.google.co m...
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
fd*************@yahoo.com
(Remove 'KeinSpam' to reply to my e-mail address)

"Juan Romero" <ju*********@bowne.com> wrote in message

news:<eu**************@TK2MSFTNGP09.phx.gbl>...
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.

"Frank Maxey" <fd*****@yahoo.com> wrote in message
news:12**************************@posting.google.c om...
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
.
.
.
Me.DialogResult = DialogResult.OK
Me.Hide()
End Sub
The call to the form is:

Dim frm As EntryForm

frm = New EntryForm()

Dim res as DialogResult = frm.ShowDialog()

If res = DialogResult.OK Then
< Service OK response>
End If

frm = Nothing
The Save button click service is definitely called but the result in
the
calling form always shows DialogResult.Cancel. If I step through the
code, the DialogResult is set to OK up to and including the Hide
method
call. However, the result is always Cancel.

I've tried changing the code to:

frm.ShowDialog()
Dim res as DialogResult = frm.DialogResult

with no success

I'm missing something obvious here, but I don't know what.

TIA

Frank Maxey
fd*************@yahoo.com
(Remove 'KeinSpam' to reply to my e-mail address)

Nov 20 '05 #6

P: n/a
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
fd*************@yahoo.com
(Remove 'KeinSpam' to reply to my e-mail address)

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:<#0**************@TK2MSFTNGP10.phx.gbl>...
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

"Frank Maxey" <fd*****@yahoo.com> wrote in message
news:12*************************@posting.google.co m...
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
fd*************@yahoo.com
(Remove 'KeinSpam' to reply to my e-mail address)

"Juan Romero" <ju*********@bowne.com> wrote in message

news:<eu**************@TK2MSFTNGP09.phx.gbl>...
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.

"Frank Maxey" <fd*****@yahoo.com> wrote in message
news:12**************************@posting.google.c om...
> 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
>
>
> .
> .
> .
> Me.DialogResult = DialogResult.OK
> Me.Hide()
> End Sub
>
>
> The call to the form is:
>
> Dim frm As EntryForm
>
> frm = New EntryForm()
>
> Dim res as DialogResult = frm.ShowDialog()
>
> If res = DialogResult.OK Then
> < Service OK response>
> End If
>
> frm = Nothing
>
>
> The Save button click service is definitely called but the result in
> the
> calling form always shows DialogResult.Cancel. If I step through the
> code, the DialogResult is set to OK up to and including the Hide
> method
> call. However, the result is always Cancel.
>
> I've tried changing the code to:
>
> frm.ShowDialog()
> Dim res as DialogResult = frm.DialogResult
>
> with no success
>
> I'm missing something obvious here, but I don't know what.
>
> TIA
>
> Frank Maxey
> fd*************@yahoo.com
> (Remove 'KeinSpam' to reply to my e-mail address)

Nov 20 '05 #7

P: n/a
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" <fd*****@yahoo.com> wrote in message
news:12**************************@posting.google.c om... 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
fd*************@yahoo.com
(Remove 'KeinSpam' to reply to my e-mail address)

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message

news:<#0**************@TK2MSFTNGP10.phx.gbl>...
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

"Frank Maxey" <fd*****@yahoo.com> wrote in message
news:12*************************@posting.google.co m...
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
fd*************@yahoo.com
(Remove 'KeinSpam' to reply to my e-mail address)

"Juan Romero" <ju*********@bowne.com> wrote in message

news:<eu**************@TK2MSFTNGP09.phx.gbl>...
> 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.
>
> "Frank Maxey" <fd*****@yahoo.com> wrote in message
> news:12**************************@posting.google.c om...
> > 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 > >
> >
> > .
> > .
> > .
> > Me.DialogResult = DialogResult.OK
> > Me.Hide()
> > End Sub
> >
> >
> > The call to the form is:
> >
> > Dim frm As EntryForm
> >
> > frm = New EntryForm()
> >
> > Dim res as DialogResult = frm.ShowDialog()
> >
> > If res = DialogResult.OK Then
> > < Service OK response>
> > End If
> >
> > frm = Nothing
> >
> >
> > The Save button click service is definitely called but the result in > > the
> > calling form always shows DialogResult.Cancel. If I step through the > > code, the DialogResult is set to OK up to and including the Hide
> > method
> > call. However, the result is always Cancel.
> >
> > I've tried changing the code to:
> >
> > frm.ShowDialog()
> > Dim res as DialogResult = frm.DialogResult
> >
> > with no success
> >
> > I'm missing something obvious here, but I don't know what.
> >
> > TIA
> >
> > Frank Maxey
> > fd*************@yahoo.com
> > (Remove 'KeinSpam' to reply to my e-mail address)

Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.