Solved

open form inside mdi parent

Posted on 2010-11-29
11
747 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 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