Skip to main content
A newer version of this page is available. .

LayoutControlItem Class

Displays an embedded control and an optional label.

Namespace: DevExpress.XtraLayout

Assembly: DevExpress.XtraLayout.v18.1.dll

Declaration

public class LayoutControlItem :
    LayoutItem,
    IContextItemCollectionOptionsOwner,
    IContextItemCollectionOwner

Remarks

A LayoutControlItem object can display an external control and a text description next to the control. The item’s control is specified by the LayoutControlItem.Control property, the text description is specified by the BaseLayoutItem.Text property. The item’s text can be hidden by setting the BaseLayoutItem.TextVisible property to false.

LayoutControlItem_structure

A layout item can be created as follows:

When a control is assigned to the LayoutControlItem.Control property, it is automatically added to the LayoutControl.Controls collection. After a control has been assigned to the LayoutControlItem.Control property, this property cannot be changed. Changing the bound control’s properties that affect its visibility and position (for instance, Location, Parent, Size, Visible and Enabled) has no effect, use the properties provided by the LayoutControlItem class instead.

When an item is disposed of at runtime, its control is not destroyed.

Note

To allow a Layout Control’s layout to be customized and serialized, you need to ensure that Name properties of the layout items and controls within the layout items are set to unique values. You must set the Name properties to unique values for layout items and controls that are created at runtime. The control’s Name property must be initialized before this control is assigned to the LayoutControlItem.Control property.

Example

The following example shows how to create a LayoutControl control and add layout items to it.

The example shows different ways to add visible and hidden layout items to the Layout Control.

CreateLayoutItems_ex

Note

To allow a Layout Control’s layout to be customized and serialized, ensure that the Name properties of the layout items and their controls are set to unique values. The control’s Name property must be initialized before this control is assigned to the LayoutControlItem.Control property.

using DevExpress.XtraLayout;
using DevExpress.XtraEditors;

LayoutControl lc = new LayoutControl();
lc.Dock = System.Windows.Forms.DockStyle.Fill;
this.Controls.Add(lc);

//Create a layout item and add it to the root group.    
LayoutControlItem item1 = lc.Root.AddItem();
// Set the item's Control and caption.
item1.Name = "Layout Item 1";
Control textBox1 = new TextEdit();
textBox1.Name = "TextBox1";
item1.Control = textBox1;
item1.Text = "Name";

// Create a new layout item.
LayoutControlItem item2 = new LayoutControlItem();
// Add the item to the root group by setting its parent.
item2.Parent = lc.Root;
item2.Name = "Layout Item 2";
Control textBox2 = new TextEdit();
textBox2.Name = "TextBox2";
item2.Control = textBox2;
item2.Text = "E-mail";

// Create a hidden layout item.
LayoutControlItem item3 = new LayoutControlItem();
item3.Name = "Layout Item 3";
lc.HiddenItems.AddRange(new BaseLayoutItem[] { item3 });
Control textBox3 = new MemoEdit();
textBox3.Name = "TextBox3";
item3.Control = textBox3;
item3.Text = "Notes";

The following code snippets (auto-collected from DevExpress Examples) contain references to the LayoutControlItem class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

Inheritance

See Also