?
Solved

open form inside mdi parent

Posted on 2010-11-29
11
Medium Priority
?
762 Views
Last Modified: 2012-06-21
How can I make this popup open up side the parent.   Thanks
mhctype = "Refer_T"
            Dim popup As New frmMHreferredProvider
            Dim myParent = Me.MdiParent
            With popup
                If popup.ShowDialog = Windows.Forms.DialogResult.OK Then
                    For Each itm As Object In popup.ListBox1.SelectedItems
                        Me.ListBox1.Items.Add(CType(itm, DataRowView).Item("strData").ToString)
                    Next
                End If
            End With

Open in new window

0
Comment
Question by:running32
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 34231558
You cannot make an MDI Child form modal by calling ShowDialog.  The dialog form must be a top level form.

What exactly are you trying to do?
Maybe there are alternatives.
0
 

Author Comment

by:running32
ID: 34231652
I am opening a form with a list box it on it.  When items are selected in the 2nd form list box they need to populate the 1st form listbox.

This works but the 2nd form opens up outside the mdi parent.

Thanks


formMHClientcontact

Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If mhclock <> True Then
            mhctype = "Refer_T"
            Dim popup As New frmMHreferredProvider
            Dim myParent = Me.MdiParent
            With popup
                If popup.ShowDialog = Windows.Forms.DialogResult.OK Then
                    For Each itm As Object In popup.ListBox1.SelectedItems
                        Me.ListBox1.Items.Add(CType(itm, DataRowView).Item("strData").ToString)
                    Next
                End If
            End With
         

        End If
    End Sub


frmMHreferredProvider

 Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.Click
        Dim drv As DataRowView = DirectCast(Me.ListBox1.SelectedItems(0), DataRowView)
        dataid = drv.Item("lngDataid")
    End Sub

Open in new window

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 34231787
For an MdiChild to be "modal" you'd basically have to disable all other MdiChildren and any controls on the MdiParent until the user dismisses the dialog...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 32

Expert Comment

by:Erick37
ID: 34231808
That is the behavior of a dialog form.  You can't show a modal form as an mdi child -- why would you need to?  You cannot access any other part of your application as long as the modal form is open.

Alternatively, you may be able to make the 'popup' form always on top of the other forms.  This might be acomplished using some API calls, but is not normal behavior of a well behaved MDI child form.
0
 

Author Comment

by:running32
ID: 34232292
sorry I'm lost.  It doesn't open as a child form.

It opens as a sperate form.  Does this mean I cannot open it inside the parent form.

Thanks
0
 
LVL 32

Expert Comment

by:Erick37
ID: 34232337
Right.  You cannot open a form using ShowDialog() "inside" the MDI parent form.
0
 

Author Comment

by:running32
ID: 34232527
Ok, so if
I have the ShowDialog open from this form I want open another form can I do that.

If so how can I declare the midi parent again.  The parent name if frmMain without declaring it as new.  Thanks

    Dim frmnew As New frmMHReferal
        With frmnew
            .Show()
        End With
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 668 total points
ID: 34232634
Not sure about your last question there...can you rephrase it?

Here is a crude example of my comment back here:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_26644637.html#34231787
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' display some other MdiChildren
        Dim f2 As New Form2
        f2.MdiParent = Me
        f2.Show()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ' display "f3" as a "modal" MdiChild
        Dim f3 As New Form3
        ShowModalChild(f3)
    End Sub

    Private Sub ShowModalChild(Optional ByVal frm As Form = Nothing)
        If Not IsNothing(frm) Then
            frm.MdiParent = Me
            AddHandler frm.FormClosed, AddressOf Form_FormClosed
            frm.MaximizeBox = False ' <-- prevent "dialog" from being maximized
            frm.Show()
            frm.WindowState = FormWindowState.Normal ' <-- make sure it's not maximized
        End If

        SetState(Me, IIf(IsNothing(frm), True, False))
        For Each child As Form In Me.MdiChildren
            If Not (child Is frm) Then
                child.Enabled = IIf(IsNothing(frm), True, False)
            End If
        Next
    End Sub

    Private Sub SetState(ByVal cont As Control, ByVal state As Boolean)
        For Each ctl As Control In cont.Controls
            If Not (TypeOf ctl Is MdiClient) Then
                ctl.Enabled = state
                If ctl.HasChildren Then
                    SetState(ctl, state)
                End If
            End If
        Next
    End Sub

    Private Sub Form_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs)
        ShowModalChild()
    End Sub

End Class

Open in new window

Idle-Mind-374496.flv
0
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 664 total points
ID: 34233070
You can do this to open a new child form from the Dialog form:
Open your Modal form from an MDI Child and set the Owner to the MDI Parent form.

        Dim frm As New frmMHreferredProvider
        frm.Owner = Me.MdiParent
        frm.ShowDialog()

To open the new Child form:

        Dim frmnew As New frmMHReferal
        frmnew.MdiParent = Me.Owner
        frmnew.Show()
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 668 total points
ID: 34233139
But you would not be able to access the new form unless you close the modal form.

>It opens as a sperate form.
It appears on top of the main form. Does the separate button in taskbar bother you? Set form property ShowInTaskbar = False
0
 

Author Comment

by:running32
ID: 34240821
thanks guys.  I'm working on the solution now.  You have all been really helpful
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question