Form Constructor Issues with Parent Form

Peter Allen
Peter Allen used Ask the Experts™
on
Experts,

A few days back I asked a question regarding passing a reference to a Form in a Public Property.  I did get an answer, but given the number of responses, tme and points involved I decided to accept a solution and ask a new question providing updated code to clarify what I might be missing.

JamesBurger's suggestion of using a Constructor on the Panel_Form seamed the best way to access subroutines and functions on the main form from the child form.

The situation is a bit more simplified.  I removed some controls which created more of a problem and simplified the structure of the Designer form I am using.  This setup is not using a MIDI form in this case.

I have a form with the following controls:
1. frmDataGridView_Designer           <-- Main Form
2. MenuStrip1                                    <-- Menu for Form
3. Panel_Menu                                    <-- Holds the ToolStrip (Buttons and Text)
4. ToolStrip_Project                            <-- ToolStrip holding buttons with Text/Graphics
5. Panel_Form                                    <-- Form showing the various Forms I use for
                                                                the Designer
6. Panel_Data                                      <-- Form showing results and Catalogs
7. StatusStrip1                                    <-- Shows current record status and Edit mode

The Panel_Form and Panel_Data Panels show Forms that are not TopLevel.  I chose this method because the size of the forms is consistant and this approach makes it much easier to create the UI I wanted for my users.

There are two forms I have created which will be viewed in Panel_Form and Panel_Data.

Panel_Form will display frmDataGridView_Editor
Panel_Data will display frmDataGridView_Catalog

So far I have the code which creates a f_PanelForm form shown below:

        Dim f_PanelForm As New frmDataGridViewProject_Editor(DirectCast(Me.ParentForm, frmDataGridViewProject_Designer))
        f_PanelForm.TopLevel = False
        f_PanelForm.Parent = Me
        f_PanelForm.m_sFormFlagRecordEdit = "View"
        Panel_Form.Controls.Add(f_PanelForm)
        f_PanelForm.Show()

Open in new window


In the code for frmDataGridView_Editor I have the constructor which gets the reference to the Designer form:

I defined the following variable on the Editor form:
    Private f_frmDesigner As frmDataGridViewProject_Designer

Open in new window


And the Constructor which gets the reference:
    Public Sub New(ByVal f_Designer As frmDataGridViewProject_Designer)

        Call InitializeComponent()
        f_frmDesigner = f_Designer

    End Sub

Open in new window


Using this method I could call the Public subroutines or functions as needed like the following:

f_frmDesigner.subFormStateStatusBar(aStatusBarList)

Open in new window


The form is displayed properly.  However when the subFormStateStatusBar is called I get the error, "object reference not set to an instance of an object" highlighting the line I use to call the subroutine.

I thought this method would work according to the solution presented, but I must be missing something???

Of the examples shown I chose this approach because it seams more direct for what I want to do.
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:
Just change:

    Dim f_PanelForm As New frmDataGridViewProject_Editor(DirectCast(Me.ParentForm, frmDataGridViewProject_Designer))

To:

    Dim f_PanelForm As New frmDataGridViewProject_Editor(Me)
Peter AllenIT Specialist

Author

Commented:
Thank you Idle_Mind!  Worked like a charm.
Peter AllenIT Specialist

Author

Commented:
Very much appreciated.

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