Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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.

CreateGroup_ex

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

LayoutControl lc = new LayoutControl();
lc.Dock = System.Windows.Forms.DockStyle.Fill;
this.Controls.Add(lc);
// Lock the layout control to prevent excessive updates.
lc.BeginUpdate();
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.
    lc.Root.Add(group1);
}
finally {
    // Unlock and update the layout control.
    lc.EndUpdate();
}