Solved

open form inside mdi parent

Posted on 2010-11-29
11
743 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
  • 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 85

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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 85

Accepted Solution

by:
Mike Tomlinson earned 167 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 166 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 167 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now