Skip to main content

How to: Create layout groups and items in code

  • 2 minutes to read

The following example shows how to create a group within the LayoutControl’s root group and add two layout items to it. A group is created using its constructor and added to the root group with the LayoutGroup.Add method.

The first layout item is created using the group’s LayoutControlGroup.AddItem method.

The second item is created using the LayoutControlItem‘s constructor. It’s then positioned to the right of the first item using the BaseLayoutItem.Move method.


using DevExpress.XtraLayout;
using DevExpress.XtraLayout.Utils;

LayoutControl lc = new LayoutControl();
lc.Dock = System.Windows.Forms.DockStyle.Fill;
// Lock the layout control to prevent excessive updates.
try {
    // Hide the root group's border and caption.
    lc.Root.GroupBordersVisible = false;
    // Create a new Details group.
    LayoutControlGroup group1 = new LayoutControlGroup();
    group1.Name = "GroupDetails";
    group1.Text = "Details";
    // Create a layout item within the group.
    LayoutControlItem item1 = group1.AddItem();
    // Bind a control to the layout item.
    TextEdit textEdit1 = new TextEdit();
    textEdit1.Name = "TextEdit1";
    item1.Control = textEdit1;
    item1.Text = "Name";

    // Create a layout item that will display a date editor.
    DateEdit dtEdit1 = new DateEdit();
    dtEdit1.Name = "dtEdit1";
    LayoutControlItem item2 = new LayoutControlItem(lc, dtEdit1);
    item2.Text = "Date";
    // Position this item to the right of item1
    item2.Move(item1, InsertType.Right);
    // Add the created group to the root group.
finally {
    // Unlock and update the layout control.