Dear All,

I am new to VB2010 and writing a MDI child form to open another form as dialogbox, then pass a value back to the MDI child form, the value is successfully passed back to the MDI child form but it can't be shown on a text box, my code as below, can somebody help on this

(on mdiForm1)

Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
Dim F As New Form
F = Form2
F.ShowDialog()
End Sub

Public Sub setText(ByVal nsc As String)
MessageBox.Show(nsc) 'it shows the correct value on screen
txtStaffCode.Text = nsc
End Sub

(on Form2)

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Dim nsc As String = lblNewCode.Text
Call mdiForm1.setText(nsc)
Me.Close()
End Sub

Edited 5 Years Ago by vr2viv: n/a

Thanks for your reply, Fa3hed!
Sorry that I have confused, should I put your code on Form2? But I need to pass the value from Form2 to the mdiForm1. And I also test the code below on mdiForm1, but not work neither.

Me.txtStaffCode.Text = Form2.lblNewCode.Text

Edited 5 Years Ago by vr2viv: n/a

the mdi form name is "frmAdminMainMenu"
the value will be passed back from "frmAddNewStaffCode"

Suppose you are having two forms example..form1 and form2 both contain textbox...
abd you want to pass values from textbox of form1 to textbox of form2
You have to First Of All have to load Form2 and should enter following code...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              Form2.Show()
        Form2.TextBox1.Text = Me.TextBox1.Text
    End Sub


Similarly you can do for MDI form

Suppose you are having two forms example..form1 and form2 both contain textbox...
abd you want to pass values from textbox of form1 to textbox of form2
You have to First Of All have to load Form2 and should enter following code...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              Form2.Show()
        Form2.TextBox1.Text = Me.TextBox1.Text
    End Sub


Similarly you can do for MDI form

Yes, you are correct, I want to pass value from textbox of form1 to mdichild form2.
Firstly, on mdichild form2, it's included a button to show the form1 by the code below

form1.ShowDialog()

Secondly, on form1, it will do some calculation and show the result on a textbox, and it will then pass the value to the mdichild form2 and show the value on a textbox whick in the mdichild form2 when I click the button on form1, I'm using send ByVal to passed the value back to mdichild fomr2

I tried to using the same coding on both standard window form instead of using mdichild form, it works fine and the value can be shown on the textbox in form2. I really don't know what's wrong when using mdichild form

the solution doesn't work because i am using vb 2008

I cannot find a function to convert my project to vb 2008, sorry

In your context only Form1 is a child form....
Am I right.....

yes

Is that attached project working....

yes, that's work, once you running the project, a MDIParent form will be shown on the screen, click the button marked with "Form1" on the toolstrip to open the MDIChild form "Form1", an "Add" button and a textbox on "Form1", you can click the "Add" button to open the "Form2" as a dialog, then you can type a word on the textbox which on "Form2" and click the "OK" button, it should then send the value back to "Form1" and placed in the textbox which in "Form1"

PS. the value was passed back to "Form1", I can use the Message.Show(a) to prompt the value on screen, but the value could not be placed in the textbox.

I have fixed it, finally, I changed the coding on Form2 as below, thanks guys!

Public Class Form2
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Dim r As String = txtResult.Text
Dim f As Form
For Each f In MDIParent1.MdiChildren
If f.Name = "Form1" Then
Dim a As Form1 = f
Call a.setText(r)
a.Focus()
End If
Next
Me.Close()
End Sub
End Class

Comments
v.good your friend fa3hed

Ok....
I thought you want to pass value from Form1->MDIChild to Form2->Not an MDIchild...
The Code in The attached WindowsApplication1 works on this context and not vice versa...
any ways you have got the code you want....

This question has already been answered. Start a new discussion instead.