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
Related API Members
The following members accept/return LayoutControlItem objects:
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.
A layout item can be created as follows:
- via the LayoutControlGroup.AddItem method of the layout group. The created item is automatically added to this group in this case.
- via the LayoutControlItem constructor. The layout item should then be added to the group manually (via the LayoutGroup.Add or BaseLayoutItem.Move method or by assigning the item’s BaseLayoutItem.Parent property to the group that the item should be displayed in);
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.
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";
Related GitHub Examples
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.