VB .Net Form Instances

SheldonC
SheldonC used Ask the Experts™
on
I am creating an application that would allow the user to save Employee records. The user can have multiple employee forms open at the same time. I have a save button at the bottom of the form but I also want to give the user the option of clicking a save button on the menu strip.

How do I code the save button to save for the form instance that has focus?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
Sounds like you are using an MDI container approach?...

If yes, then grab the active child form with the ActiveMdiChild() property:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.activemdichild.aspx

Just cast it to whatever type your Mdi Children are:

    If Not IsNothing(Me.ActiveMdiChild) Then
        Dim frm As YourMdiChildTypeHere = CType(Me.ActiveMdiChild, YourMdiChildTypeHere)
        frm.CallYourSaveMethod()
        ' ... or click the button on it ...
        frm.btnSave.PerformClick()
    End If

Author

Commented:
I am not quite sure what you are referring to as my mdi child type. I am pretty much a beginner so I am learning as I go. :)
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
If your MdiChildren are instances of Form2, then you'd replace YouMdiChildTypeHere with Form2.

Basically you need to place the NAME (type) of your MdiChildren in there.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial