9 Replies - 778 Views - Last Post: 18 September 2014 - 11:49 AM Rate Topic: -----

#1 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3517
  • View blog
  • Posts: 12,008
  • Joined: 12-December 12

ShowDialog Form property is empty

Posted 20 October 2013 - 06:39 AM

I have two of the simplest forms, with a couple of Buttons and a TextBox. I click to open the second form (frmModal) using ShowDialog(), type some text into txtGreeting and press the Yes button. What should happen is that a MessageBox appears confirming the text that was entered into txtGreeting, but it is empty.

I understand that the Form's properties should be accessible until the form goes out of scope, but they disappear straight-away. I can't even read dialog.txtGreeting.Text.

Am I missing anything obvious please?

Public Class frmMain

    Private Sub btnModal_Click(sender As Object, e As EventArgs) Handles btnModal.Click
        Dim dialog As frmModal

        dialog = New frmModal()
        Dim result As DialogResult = frmModal.ShowDialog(Me)
        If result = Windows.Forms.DialogResult.Yes Then
            MessageBox.Show(dialog.Greeting)
        End If
        'dialog.Dispose()
    End Sub
End Class


Public Class frmModal
    Public Property Greeting As String
        Get
            Return txtGreeting.Text
        End Get
        Set(value As String)

        End Set
    End Property

    Private Sub btnYes_Click(sender As Object, e As EventArgs) Handles btnYes.Click
        MessageBox.Show(Greeting)
    End Sub
End Class

The Yes button has it's DialogResult property set to Yes.

I've tried moving the dialog-declaration out of the click-event, using an (unnecessary) Dispose(), deliberately assigning the Greeting property in the Yes-click event..

Posted Image

This post has been edited by andrewsw: 20 October 2013 - 06:43 AM


Is This A Good Question/Topic? 0
  • +

Replies To: ShowDialog Form property is empty

#2 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 704
  • View blog
  • Posts: 3,027
  • Joined: 03-December 12

Re: ShowDialog Form property is empty

Posted 20 October 2013 - 07:28 AM

I am on my phone as usual so I don't have my computer to verify. And no offense but when I saw who started this thread I thought it was a joke.


I have never set my classes to use the value like you have, but you have an empty setter. From my understanding, you have the return but never set the value of greeting to txtgreeting.text.
Was This Post Helpful? 1
  • +
  • -

#3 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3517
  • View blog
  • Posts: 12,008
  • Joined: 12-December 12

Re: ShowDialog Form property is empty

Posted 20 October 2013 - 07:36 AM

Hi. Well, I felt a little silly at posting because I feel it should be something obvious. But, hey, there's no reason I can't give other people the opportunity to help me :)

I don't think the Set is the problem though, as the MessageBox in the Yes-click event correctly confirms the value of Greeting.

My suspicion is that, unlike C#, the dialog-boxes properties are immediately cleared - which would be a real pain.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3517
  • View blog
  • Posts: 12,008
  • Joined: 12-December 12

Re: ShowDialog Form property is empty

Posted 20 October 2013 - 07:43 AM

Doh! My silly mistake.. I was showing frmModal, not dialog :whistling:
Was This Post Helpful? 0
  • +
  • -

#5 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 704
  • View blog
  • Posts: 3,027
  • Joined: 03-December 12

Re: ShowDialog Form property is empty

Posted 20 October 2013 - 08:12 AM

Its normally the simple things that trip you up after you conquer the basics!
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3517
  • View blog
  • Posts: 12,008
  • Joined: 12-December 12

Re: ShowDialog Form property is empty

Posted 20 October 2013 - 08:19 AM

View Postastonecipher, on 20 October 2013 - 03:12 PM, said:

Its normally the simple things that trip you up after you conquer the basics!

This was quite tricky to spot, as the code runs and there are no errors or warnings. I'll blame it on VS ;) as it would be quite simple for it to produce a squiggly when referring to the static form-instance.

But you are quite right. Sometimes it is easy to over-think things and miss the obvious. Andy.
Was This Post Helpful? 0
  • +
  • -

#7 ebolisa  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 152
  • Joined: 22-September 09

Re: ShowDialog Form property is empty

Posted 20 October 2013 - 08:53 AM

So Andy, How did you fix line 7/8? So the rest of us can see the solution...
Was This Post Helpful? 1
  • +
  • -

#8 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3517
  • View blog
  • Posts: 12,008
  • Joined: 12-December 12

Re: ShowDialog Form property is empty

Posted 20 October 2013 - 09:01 AM

Just changing:
Dim result As DialogResult = frmModal.ShowDialog(Me)

to
Dim result As DialogResult = dialog.ShowDialog(Me)

The original code worked (that is, ran without error) but the values (Greeting, etc.) where added to the static form-instance (frmModal) not my current instance (dialog), which was instantiated but never shown.

This post has been edited by andrewsw: 20 October 2013 - 09:02 AM

Was This Post Helpful? 0
  • +
  • -

#9 ebolisa  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 152
  • Joined: 22-September 09

Re: ShowDialog Form property is empty

Posted 20 October 2013 - 09:19 AM

Thank you, though so -- it’s good for the rookies, who’re new at this, see questions followed by possible solutions. Especially when a question is posted by a guru :smile2:/>
Was This Post Helpful? 1
  • +
  • -

#10 rianbattle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-September 14

Re: ShowDialog Form property is empty

Posted 18 September 2014 - 11:49 AM

I know this is an old thread but I'd like to say thank you for posting, even if feeling silly for it. I just ran into exactly the same issue and this thread was one of the first results that popped up. Thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1