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
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"
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
And the Constructor which gets the reference:
Public Sub New(ByVal f_Designer As frmDataGridViewProject_Designer)
f_frmDesigner = f_Designer
Using this method I could call the Public subroutines or functions as needed like the following:
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.