Accessing childform-properties


Author
Message
Thomas Holste
Thomas Holste
StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
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
StrataFrame Team
S
StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
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
Thomas Holste
Thomas Holste
StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi Ben,

thanks for your help.

Best regards

Thomas
Thomas Holste
Thomas Holste
StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
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  
StrataFrame Team
S
StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
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.
Edited 11 Years Ago by Ben Chase
Thomas Holste
Thomas Holste
StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi Ben,

thanks a lot, I've got it working.

Best regards

Thomas
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search