Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDI - Accessing control on one of many instances of same child form

Status
Not open for further replies.

Dimm

Programmer
Jun 26, 2001
16
GB
Hi,

I have an MDI form that can be opened many times in its parent as tabbed forms.

I have a seperate form that loads as a dialog and need to access a control on the active MDI child form. I press a button on the dialog and need to pass a datarow to a grid control on the active MDI child.

What I am struggling to understand is how I get the active child, determine its one of the forms I require and then access the gridcontrol on it.

Thanks in advance


 
The MDI parent can be accessed using DirectCast

Dim MDIparentForm As Formn1 = DirectCast(Form2, Form1)
Dim FormINeed as Form3 = MDIParentForm.Activechild

FormIneed can then be accessed directly.
 
A more elegant solution without having to cast forms is to pass the active MDI child as a parameter to the dialog. You can achieve that by either modifying or adding a constructor to the dialog:

Code:
'In the new dialog form's code:
Protected activeChild As myMDIchildForm

Public Sub New(ByRef activeMDIchild As myMDIchildForm)
  activeChild = activeMDIchild
End Sub

Private Sub MyCode()
  activeChild.GridControl1.DoYourThing ...
End Sub

Now when you show the dialog in your code, simply pass the main form's ActiveMDIChild property to construct the dialog.
If you have different kinds of MDI childs, you should chack on beforehand wether the currently active MDI child is of the right type:

Code:
...
If TypeOf Me.ActiveMDIChild Is myRightTypeOfMDIchild Then
  Dim D As New myDialog(Me.ActiveMDIChild)
  D.ShowDialog()
Else
  MsgBox("Wrong type of MDI Child active!")
End If
...

I hope you get what I mean here...

Regards, Ruffnekk
---
Basic Instructions Before Leaving Earth (B.I.B.L.E.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top