KB Article A2857
Visible to All Users

A dynamically created DockPanel loses its child controls after its layout is restored

Description:
A dock panel with a memo editor inside it is created programmatically. It works fine. When saving and restoring dock windows via the SaveToXml and RestoreFromXml methods the dock panel's position and size is restored correctly, but the panel is empty - there is no memo editor inside.

Answer:
A dock panel with the inner control must be created before a layout is loaded. Next, you must assign a value to the ID property of your DockPanel. The panel's ID must be the same as the one saved in the layout, not the newly generated GUID.

C#
using DevExpress.XtraBars.Docking; private void CreateDockPanels() { DockPanel panel1 = dockManager1.AddPanel(DockingStyle.Left); panel1.Text = "Panel 1"; panel1.ID = new Guid("{00000000-0000-0000-0000-000000000001}"); panel1.Controls.Add(new UserControl1()); DockPanel panel2 = dockManager1.AddPanel(DockingStyle.Right); panel2.Text = "Panel 2"; panel2.ID = new Guid("{00000000-0000-0000-0000-000000000002}"); panel2.Controls.Add(new UserControl2()); }
Visual Basic
Imports DevExpress.XtraBars.Docking Private Sub CreateDockPanels() Dim panel1 As DockPanel = dockManager1.AddPanel(DockingStyle.Left) panel1.Text = "Panel 1" panel1.ID = New Guid("{00000000-0000-0000-0000-000000000001}") panel1.Controls.Add(New UserControl1()) Dim panel2 As DockPanel = dockManager1.AddPanel(DockingStyle.Right) panel2.Text = "Panel 2" panel2.ID = New Guid("{00000000-0000-0000-0000-000000000002}") panel2.Controls.Add(New UserControl2()) End Sub

See Also:
Why are the Items created in code not restored when loading settings?

Comments (2)

    hi,
    I'm dynamically reloading my DockLayoutManager
    The saved layoutstream that I have correctly has my layoutPanel as Item2 in the ITems collection.
    However, when I try to get the item after calling DockLayoutManager.RestoreFromLayoutStream(layout);
    DockLayoutManager.GetItem("Pivot_1f380fe90d52429ea3fed0dc509cb385_LayoutPanel") returns null yet
    DockLayoutManager.GetItem("dockItem1") correctly returns the first item. Why is this? I cannot seem to access the layoutPanels from the layoutstream after calling RestoreFromLayout.
    <?xml version="1.0"?>
    -<XtraSerializer application="DockLayoutManager" version="1.0"> <property isnull="true" name="#LayoutVersion"/> -<property name="$DockLayoutManager" value="DockLayoutManager" iskey="true"> <property name="ManualClosedPanelsBarVisibility">false</property> -<property name="Items" value="2" iskey="true"> -<property isnull="true" name="Item1" iskey="true"> <property isnull="true" name="ParentCollectionName"/> <property isnull="true" name="ParentName"/> <property name="TypeName">LayoutGroup</property> <property name="SerializableSelectedTabPageIndex">-1</property> <property name="Orientation">Horizontal</property> <property name="Name">dockItem1</property> </property> -<property isnull="true" name="Item2" iskey="true"> <property name="ParentName">dockItem1</property> <property name="TypeName">LayoutPanel</property> <property name="AllowRename">true</property> <property name="AllowHide">false</property> <property name="SerializableFloatingOffset">0,0</property> <property name="AllowDockToDocumentGroup">false</property> <property isnull="true" name="ParentCollectionName"/> <property name="Caption" type="System.String">Pivot Grid</property> <property name="Name">Pivot_1f380fe90d52429ea3fed0dc509cb385_LayoutPanel</property> </property> </property> </property> </XtraSerializer>

    DevExpress Support Team 12 years ago

      Hi,
      In order not to mix several problems in one thread, I have opened a separate issue on your behalf:
      How to properly save and restore layout using the DockManager
      Please refer to this report for further correspondence on this item.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.