hey guys,

I have this simple set a codes that opens a form as a child in MDI container.

Private Sub BarButtonItem1_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick

        frmConfirmShipment.MdiParent = Me
        frmConfirmShipment.Show()

        ''Dim NewMDIChild As New frmConfirmShipment() With {.MdiParent = Me}
        ''For Each ChildForm As Form In Me.MdiChildren
        ''If ChildForm.Name = NewMDIChild.Name Then
        ''ChildForm.Focus()
        ''Exit Sub
        ''End If
        ''Next
        ''NewMDIChild.Show()
    End Sub

When i run this set of codes, system keep telling me that same form cannot be both mdichild and mdiparent, however, I never set my child form as a parent.
Someone please help~!

Dani AI

Generated

— the exception means the same Form object is being treated as both an MDI container and an MDI child. ’s remark points in the right direction: something in the project has marked the shipment form (or the instance being used) as an MDI parent, so when code tries to make it a child the framework throws that error.

Quick, no‑nonsense checklist (compare the problem form against one that works):

  • Verify the form’s IsMdiContainer property is False (open the form in the Designer and check the Properties window, or search the form’s Designer.vb for any assignment to IsMdiContainer).
  • Search the project for any code that sets MdiParent or IsMdiContainer on that form (including code in a base form if the form inherits from another form).
  • Confirm the MDI container form really has IsMdiContainer = True and that the MdiParent being assigned is the container instance (not another child or an unintended default instance).
  • Avoid reusing a configured instance: use a fresh instance of the child form when adding it to the MDI parent (the default VB form instance can sometimes carry unexpected settings).

Extra notes and gotchas:

  • A child must not be an MDI container; the Designer can accidentally set that flag.
  • Modal dialogs should use a dialog pattern (no MdiParent) rather than mixing modal and MDI roles.
  • If the problem persists, inspect the form’s Designer.vb around generated initialization lines to find where the conflicting property is set; the offending assignment is usually visible there.

This addresses the common causes without changing the overall MDI approach; resolving the IsMdiContainer / instance mismatch normally fixes the error.

Recommended Answers

All 3 Replies

This is the exact error message

Form cannot be both an MDI child and MDI parent.
Parameter name: value

You set the form to be MDI parent in your code and you still expect it to open in itself.

You set the form to be MDI parent in your code and you still expect it to open in itself.

what do you mean? I've been trying to figure this our all day and am very frustrated so please bare with me.
I don't know that you mean by 'open in itself'

I am trying to open a form called frmConfirmShipment from frmMain which is the MDI parent for all of my other forms. I have about 14 other forms that opens in MDI container without any problem but this one would keep giving me error message.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.