Problem with DialogResult property

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Maxey

    Problem with DialogResult property

    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(B yVal sender As System.Object, _
    ByVal e As System.EventArg s) Handles btnSave.Click


  • William Ryan eMVP

    #2
    Re: Problem with DialogResult property

    Frank:

    Have you set the AcceptButton and CancelButton and/or are you setting the
    dialogresult within the form?
    "Frank Maxey" <fdmaxey@yahoo. com> wrote in message
    news:12e3e52d.0 405060931.6553e a42@posting.goo gle.com...[color=blue]
    > 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(B yVal sender As System.Object, _
    > ByVal e As System.EventArg s) 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.Ca ncel. 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.DialogResul t
    >
    > with no success
    >
    > I'm missing something obvious here, but I don't know what.
    >
    > TIA
    >
    > Frank Maxey
    > fdmaxeyKeinSpam @yahoo.com
    > (Remove 'KeinSpam' to reply to my e-mail address)[/color]


    Comment

    • William Ryan eMVP

      #3
      Re: Problem with DialogResult property

      Frank, I just saw you did, my oversight.
      "Frank Maxey" <fdmaxey@yahoo. com> wrote in message
      news:12e3e52d.0 405060931.6553e a42@posting.goo gle.com...[color=blue]
      > 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(B yVal sender As System.Object, _
      > ByVal e As System.EventArg s) 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.Ca ncel. 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.DialogResul t
      >
      > with no success
      >
      > I'm missing something obvious here, but I don't know what.
      >
      > TIA
      >
      > Frank Maxey
      > fdmaxeyKeinSpam @yahoo.com
      > (Remove 'KeinSpam' to reply to my e-mail address)[/color]


      Comment

      • Juan Romero

        #4
        Re: Problem with DialogResult property

        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" <fdmaxey@yahoo. com> wrote in message
        news:12e3e52d.0 405060931.6553e a42@posting.goo gle.com...[color=blue]
        > 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(B yVal sender As System.Object, _
        > ByVal e As System.EventArg s) 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.Ca ncel. 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.DialogResul t
        >
        > with no success
        >
        > I'm missing something obvious here, but I don't know what.
        >
        > TIA
        >
        > Frank Maxey
        > fdmaxeyKeinSpam @yahoo.com
        > (Remove 'KeinSpam' to reply to my e-mail address)[/color]


        Comment

        • Frank Maxey

          #5
          Re: Problem with DialogResult property

          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
          fdmaxeyKeinSpam @yahoo.com
          (Remove 'KeinSpam' to reply to my e-mail address)



          "Juan Romero" <juan.romero@bo wne.com> wrote in message news:<eudFhd5ME HA.2484@TK2MSFT NGP09.phx.gbl>. ..[color=blue]
          > 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" <fdmaxey@yahoo. com> wrote in message
          > news:12e3e52d.0 405060931.6553e a42@posting.goo gle.com...[color=green]
          > > 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(B yVal sender As System.Object, _
          > > ByVal e As System.EventArg s) 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.Ca ncel. 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.DialogResul t
          > >
          > > with no success
          > >
          > > I'm missing something obvious here, but I don't know what.
          > >
          > > TIA
          > >
          > > Frank Maxey
          > > fdmaxeyKeinSpam @yahoo.com
          > > (Remove 'KeinSpam' to reply to my e-mail address)[/color][/color]

          Comment

          • Jay B. Harlow [MVP - Outlook]

            #6
            Re: Problem with DialogResult property

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

            On the DialogForm form:
            Form.AcceptButt on = buttonSave
            Form.CancelButt on = buttonCancel

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

            On the buttonCancel button:
            Button.DialogRe sult = DialogResult.Ca ncel


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

            Alternatively, if you set Form.DialogResu lt 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" <fdmaxey@yahoo. com> wrote in message
            news:12e3e52d.0 405070413.37809 7d@posting.goog le.com...[color=blue]
            > 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
            > fdmaxeyKeinSpam @yahoo.com
            > (Remove 'KeinSpam' to reply to my e-mail address)
            >
            >
            >
            > "Juan Romero" <juan.romero@bo wne.com> wrote in message[/color]
            news:<eudFhd5ME HA.2484@TK2MSFT NGP09.phx.gbl>. ..[color=blue][color=green]
            > > I have had this problem before and the only thing I can tell you (since[/color][/color]
            I[color=blue][color=green]
            > > never figured it out) is make your own form property. That works.
            > >
            > > "Frank Maxey" <fdmaxey@yahoo. com> wrote in message
            > > news:12e3e52d.0 405060931.6553e a42@posting.goo gle.com...[color=darkred]
            > > > 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(B yVal sender As System.Object, _
            > > > ByVal e As System.EventArg s) 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.Ca ncel. 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.DialogResul t
            > > >
            > > > with no success
            > > >
            > > > I'm missing something obvious here, but I don't know what.
            > > >
            > > > TIA
            > > >
            > > > Frank Maxey
            > > > fdmaxeyKeinSpam @yahoo.com
            > > > (Remove 'KeinSpam' to reply to my e-mail address)[/color][/color][/color]


            Comment

            • Frank Maxey

              #7
              Re: Problem with DialogResult property

              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.DialogResu lt = 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
              fdmaxeyKeinSpam @yahoo.com
              (Remove 'KeinSpam' to reply to my e-mail address)

              "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message news:<#0G9ReDNE HA.1104@TK2MSFT NGP10.phx.gbl>. ..[color=blue]
              > Frank,
              > Normally what I do is what William Ryan was asking about.
              >
              > On the DialogForm form:
              > Form.AcceptButt on = buttonSave
              > Form.CancelButt on = buttonCancel
              >
              > On the buttonSave button:
              > Button.DialogRe sult = DialogResult.Ok
              >
              > On the buttonCancel button:
              > Button.DialogRe sult = DialogResult.Ca ncel
              >
              >
              > The Form will automatically handle setting Form.DialogResu lt & calling
              > Form.Hide when you click either button, or press the Enter or Cancel key.
              >
              > Alternatively, if you set Form.DialogResu lt 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" <fdmaxey@yahoo. com> wrote in message
              > news:12e3e52d.0 405070413.37809 7d@posting.goog le.com...[color=green]
              > > 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
              > > fdmaxeyKeinSpam @yahoo.com
              > > (Remove 'KeinSpam' to reply to my e-mail address)
              > >
              > >
              > >
              > > "Juan Romero" <juan.romero@bo wne.com> wrote in message[/color]
              > news:<eudFhd5ME HA.2484@TK2MSFT NGP09.phx.gbl>. ..[color=green][color=darkred]
              > > > I have had this problem before and the only thing I can tell you (since[/color][/color]
              > I[color=green][color=darkred]
              > > > never figured it out) is make your own form property. That works.
              > > >
              > > > "Frank Maxey" <fdmaxey@yahoo. com> wrote in message
              > > > news:12e3e52d.0 405060931.6553e a42@posting.goo gle.com...
              > > > > 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(B yVal sender As System.Object, _
              > > > > ByVal e As System.EventArg s) 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.Ca ncel. 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.DialogResul t
              > > > >
              > > > > with no success
              > > > >
              > > > > I'm missing something obvious here, but I don't know what.
              > > > >
              > > > > TIA
              > > > >
              > > > > Frank Maxey
              > > > > fdmaxeyKeinSpam @yahoo.com
              > > > > (Remove 'KeinSpam' to reply to my e-mail address)[/color][/color][/color]

              Comment

              • Jay B. Harlow [MVP - Outlook]

                #8
                Re: Problem with DialogResult property

                Frank,[color=blue]
                > According to the Microsoft's documentation (I should know better by
                > now) it should be sufficient just to use:
                >
                > Form.DialogResu lt = DialogResult.OK
                > Form.Hide()[/color]

                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(B yVal sender As System.Object, _
                ByVal e As System.EventArg s) Handles btnSave.Click
                Me.DialogResult = DialogResult.OK
                End Sub

                However I prefer setting the Button.DialogRe sult & Form.AcceptButt on, 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_Clo sed(ByVal sender As Object, _
                ByVal e As System.EventArg s) Handles MyBase.Closed
                Me.DialogResult = DialogResult.Ca ncel
                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" <fdmaxey@yahoo. com> wrote in message
                news:12e3e52d.0 405100424.4956c bb6@posting.goo gle.com...[color=blue]
                > 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.DialogResu lt = 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
                > fdmaxeyKeinSpam @yahoo.com
                > (Remove 'KeinSpam' to reply to my e-mail address)
                >
                > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message[/color]
                news:<#0G9ReDNE HA.1104@TK2MSFT NGP10.phx.gbl>. ..[color=blue][color=green]
                > > Frank,
                > > Normally what I do is what William Ryan was asking about.
                > >
                > > On the DialogForm form:
                > > Form.AcceptButt on = buttonSave
                > > Form.CancelButt on = buttonCancel
                > >
                > > On the buttonSave button:
                > > Button.DialogRe sult = DialogResult.Ok
                > >
                > > On the buttonCancel button:
                > > Button.DialogRe sult = DialogResult.Ca ncel
                > >
                > >
                > > The Form will automatically handle setting Form.DialogResu lt & calling
                > > Form.Hide when you click either button, or press the Enter or Cancel[/color][/color]
                key.[color=blue][color=green]
                > >
                > > Alternatively, if you set Form.DialogResu lt within your event handler,[/color][/color]
                Hide[color=blue][color=green]
                > > is automatically called for you.
                > >
                > > Is this with VS.NET 2002 or VS.NET 2003? I could not replicate you[/color][/color]
                problem[color=blue][color=green]
                > > with VS.NET 2003.
                > >
                > > Hope this helps
                > > Jay
                > >
                > >
                > >
                > > "Frank Maxey" <fdmaxey@yahoo. com> wrote in message
                > > news:12e3e52d.0 405070413.37809 7d@posting.goog le.com...[color=darkred]
                > > > 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
                > > > fdmaxeyKeinSpam @yahoo.com
                > > > (Remove 'KeinSpam' to reply to my e-mail address)
                > > >
                > > >
                > > >
                > > > "Juan Romero" <juan.romero@bo wne.com> wrote in message[/color]
                > > news:<eudFhd5ME HA.2484@TK2MSFT NGP09.phx.gbl>. ..[color=darkred]
                > > > > I have had this problem before and the only thing I can tell you[/color][/color][/color]
                (since[color=blue][color=green]
                > > I[color=darkred]
                > > > > never figured it out) is make your own form property. That works.
                > > > >
                > > > > "Frank Maxey" <fdmaxey@yahoo. com> wrote in message
                > > > > news:12e3e52d.0 405060931.6553e a42@posting.goo gle.com...
                > > > > > 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[/color][/color][/color]
                form[color=blue][color=green][color=darkred]
                > > > > > needs to check the
                > > > > > DialogResult field for an OK response.
                > > > > >
                > > > > > In my button service in the dialog form, I have:
                > > > > >
                > > > > > Private Sub btnSave_Click(B yVal sender As System.Object, _
                > > > > > ByVal e As System.EventArg s) Handles[/color][/color][/color]
                btnSave.Click[color=blue][color=green][color=darkred]
                > > > > >
                > > > > >
                > > > > > .
                > > > > > .
                > > > > > .
                > > > > > 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[/color][/color][/color]
                in[color=blue][color=green][color=darkred]
                > > > > > the
                > > > > > calling form always shows DialogResult.Ca ncel. If I step through[/color][/color][/color]
                the[color=blue][color=green][color=darkred]
                > > > > > 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.DialogResul t
                > > > > >
                > > > > > with no success
                > > > > >
                > > > > > I'm missing something obvious here, but I don't know what.
                > > > > >
                > > > > > TIA
                > > > > >
                > > > > > Frank Maxey
                > > > > > fdmaxeyKeinSpam @yahoo.com
                > > > > > (Remove 'KeinSpam' to reply to my e-mail address)[/color][/color][/color]


                Comment

                Working...