[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

VB.NET Get Property from MDIParent

I have an MDI Parent form named Main.  I am trying to pass a parameter based on which menu item a user clicked.  I tried passing the value to a property set on the form that will open (the form morphs depending on the selection) but the value clears.  So I set a property on the MDI form but when I get the value the MDI Property is blank.

Any ideas?
Private Sub cmdOrdered_Click(ByVal sender As System.Object, ByVal e As 
                  System.EventArgs) Handles cmdOrdered.Click
        Dim frm As New Main
        msReport = frm.GetReportType
        Call Me.DisplayReport()
    End Sub

Open in new window

0
CipherIS
Asked:
CipherIS
  • 3
  • 2
1 Solution
 
Thunder724Commented:
are you trying to open a specific form based on what menu item on the Main form is clicked?  Or is there only one MDI child form being called and you want a specific parameter passed to that form?
if you want to pass a paremeter to a MDI form there are a couple ways of doing it.  I like to create a friend value e.g. DIM tmpval1$ = Nothing.  Assign the variable before onpening the form and then set the object of the form that you want.  in this case i am assuming it is a String.  You can set it either from the MDI child or the parent; because in this case we are creating a FRIEND variable (which by the way I usually create in a Module)
 
0
 
CipherISAuthor Commented:
Ok, I named the variable on the MDI form as follows
Friend MDIReportType as String
There are 3 submenu items under the menu report.  The MDI calls a form named DisplayReport.  So when a user clicks on a submenu I am setting the value of MDIReportType = "ReportA" (as an example).
The DisplayReport form needs to get the value of MDIReportType so the form knows which controls to display.
How do I get the value MDIReportType (declared in the MDI form) from the DisplayReport form?
 
0
 
CipherISAuthor Commented:
I want a specific parameter passed to the form.  I created a public property on the DisplayReport form.  I set the property from the MDI form. But when I show the form the variable in the displayreport is equal to "".
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
CipherISAuthor Commented:
It worked.
Thx

    Private Sub cmdProduction_Click(ByVal sender As System.Object, 
              ByVal e As System.EventArgs) Handles cmdProduction.Click
        Dim frm As New Main
        msReport = Main.msMDIReportType
        Call Me.DisplayReport()
    End Sub

Open in new window

0
 
Thunder724Commented:
OK... on the MDI Parent form create your friendly variable
Friend MDIReportType as String = ""
 
In the Menu Item(s) Click event set this value to whatever you need it to be
e.g.  MDIReportType = "MyImportantReport"
 
Open the Report MDI Child Form....
 
Now once the MDI Child Report form is open you can reference the MDIReportType variable as you need right from the Report MDI child Form. eg..
Me.TextBox1 = MDIReportType
 
Make sense?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If you are trying to access an mdiPARENT member from the mdiCHILD then do something like this:

    ' ....in the mdiCHILD...
    Dim frm As Main = DirectCast(Me.MdiParent, Main)
    msReport = frm.msMDIReportType

The last snippet that you posted "worked" because MAIN is your startup form and you used:

    msReport = Main.msMDIReportType

The "Main" in the above line is accessing the "default instance" of the form used at startup.  If you had multiple Mains being displayed it would always access the first Main that opened when the app started.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now