StrataFrame Forum

Accessing childform-properties

http://forum.strataframe.net/Topic31850.aspx

By Thomas Holste - 2/21/2013

Hi there,

is there a way to access the public properties of a childform after being called by the parent with a childform-dialog like:

Dim nKunr as integer = 0

if me.childformxy.showdialog = dialogresult.ok

...nKunr = childformxy.nKundennr

Best regards

Thomas
By StrataFrame Team - 2/21/2013

No, there isn't, sorry.  The ChildFormDialog disposes of the created child dialog before the ShowDialog() method exits.  If you need to pass data back out of the child dialog, you could create a "parameters" class that is passed to the child form.  The child form could then set the values you need on it.  Since a class is a reference type, the object will have the values after the ShowDialog() method exits.

Internal Class MyParams
   Public nKunr As Integer
End Class

'-- Child form's constructor
Public Sub New(p As MyParams)
   '-- Save off the params to set the value
End Sub

'-- Show dialog
Dim p As New MyParams
If Me.childformxy.ShowDialog(p) = DialogResult.OK
   '-- p.nKunr has value that was set by the child form
End If
By Thomas Holste - 2/21/2013

Hi Ben,

thanks for your help.

Best regards

Thomas
By Thomas Holste - 2/21/2013

Hi Ben,

after trying it, I found problem:

Internal Class MyParams

   Public nKunr As Integer End Class

'-- Child form's constructor Public Sub New(p As MyParams)    '-- Save off the params to set the value End Sub

'-- Show dialog Dim p As New MyParams If Me.childformxy.ShowDialog(p) = DialogResult.OK    '-- p.nKunr has value that was set by the child form End If Your sample assumes that I add the needed value in the new-method but what to do with the parameter-class if I have to set the values in another procedure? I don't have access to the object outside the new-method? Best regards Thomas  
By StrataFrame Team - 2/21/2013

You will have to save off the reference in a private field of the child dialog.

Public Class MyChildForm

   Public Sub New(p as MyParams)
      Me._params = p
   End Sub

   Private _params As MyParams

   Private Sub HandleClick(sender As Object, e As EventArgs)
      '-- Set the parameter's property where ever you need
      Me._params.nKunr = 7
   End Sub

End Class

After the ShowDialog(p) exits, p.nKunr will have the proper value because p and the Me._params of the child form are the same object.
By Thomas Holste - 2/21/2013

Hi Ben,

thanks a lot, I've got it working.

Best regards

Thomas