Multiple child forms - updating the right one

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

I've got an mdiParent form. I open an instance of a child form like
this:

Dim frmChild as New frmCustomers
frmChild.Show()

I've got a few of these open at a time. On each frmChild I open
another form that displays customer data. When I make changes and save
the customer data, I need the updated data to show on the correct
frmChild. How do I know which form opened the customer data form and
how would I reference it?
 
You could use a controlling class that opens all the child forms,
specifying the mdi form as its mdiform. The controlling class can keep
track of which form has the request to open the data form, and the
controlling class can manage that also. So when the update needs to be
done, the controlling class then handles the placement of the data into
the correct form.

Tom
 
Could you give me a "for instance"?


You could use a controlling class that opens all the child forms,
specifying the mdi form as its mdiform. The controlling class can keep
track of which form has the request to open the data form, and the
controlling class can manage that also. So when the update needs to be
done, the controlling class then handles the placement of the data into
the correct form.

Tom
 
Hello Kevin,

-CALLER-
tFormVariable.Show(me)

-DATA FORM-
if not nothing is me.owner then
' We got a live one.
endif

-Boo
 
Thanks, but the .Show(Me) function won't work with MDI Child forms,
which my form needs to be.
 
Hi Kevin,
You would add code that works in the same way the MDIParent calls
the ChildForm.

eg.
Dim frmChild as New frmCustomers
frmChild.MdiParent = Me
frmChild.Show()
From the code above you now have an MDIParent with a linked Child as
you orginally stated.
Then you state you call another form from the child to amend customer
data.

eg.
Dim frmNewForm as new frmCustomerData
frmNewForm.Show()

**** THE FIX ****
In the customer data form you load from the child, you need to add a
'/ ADD TO CUSTOMER DATA FORM
Private _ParentForm As Form
Public Property ParentForm() As Form
Get
Return _ParentForm
End Get
Set(ByVal value As Form)
_ParentForm = value
End Set
End Property

Then you call the customer data form as below
Dim frmNewForm as new frmCustomerData
frmNewForm.ParentForm = frmChild
frmNewForm.Show()

This allows you from the customer data form to alter the field values
on the child form
_ParentForm.TextBox1.Text = "Joe Bloggs"

Regards,
Tony
 
When I've tried these suggestions, other forms weren't able to access
my 'CustomerData' form. So here's what I came up with in case anybody
cares or wants to do the same thing:

'Find the correct frmCustomers that opened this form and update the
grid
For X = 0 To (frmMain.MdiChildren.Length) - 1
Dim tempChild As Form = CType(frmMain.MdiChildren(X),
Form)
If tempChild.Name = "frmCustomers" Then
Dim CallingForm As frmCustomers =
DirectCast(tempChild, frmCustomers)
If CallingForm.txtCourseID.Text = Me.txtCourseID.Text
Then
CallingForm.LoadChkbox()

'Locate the updated record in the Grid1
For Y = 0 To CallingForm.Grid1.Rows.Count - 1
If CallingForm.Grid1.Rows(Y).Cells(0).Value =
txtCustomerNumber.Text Then
CallingForm.Grid1.CurrentCell =
CallingForm.Grid1.Rows(Y).Cells(1)
Exit For
End If
Next Y
Me.Close()
CallingForm.Show()
CallingForm.Grid1.Focus()
Exit For
End If
End If
Next X

When I open the CustomerData form, I fill a textbox with the customer
number on both forms. I then look for that customer number in the
textbox on all frmCustomers. It works.
 
Back
Top