Back to Devexpress

LayoutControl.Items Property

windowsforms-devexpress-dot-xtralayout-dot-layoutcontrol-e4b65046.md

latest8.0 KB
Original Source

LayoutControl.Items Property

Provides access to all the layout items owned by the LayoutControl.

Namespace : DevExpress.XtraLayout

Assembly : DevExpress.XtraLayout.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[XtraSerializableProperty(false, true, false)]
[Browsable(false)]
public ReadOnlyItemCollection Items { get; set; }
vb
<XtraSerializableProperty(False, True, False)>
<Browsable(False)>
Public Property Items As ReadOnlyItemCollection

Property Value

TypeDescription
DevExpress.XtraLayout.Utils.ReadOnlyItemCollection

A DevExpress.XtraLayout.Utils.ReadOnlyItemCollection object which represents the collection of layout items.

|

Remarks

The Items collection contains visible and hidden layout items. To access only hidden layout items, use the LayoutControl.HiddenItems property.

Example

The following code shows how to use layout item labels (BaseLayoutItem.Text) as accessible names (Control.AccessibleName) for embedded controls. When you focus an embedded editor, an accessibility client application (for instance, Microsoft Narrator) reads the specified accessible name along with the editor’s value.

csharp
using DevExpress.XtraLayout;

private void Form1_Load(object sender, EventArgs e) {
    DevExpress.XtraLayout.Utils.ReadOnlyItemCollection items = layoutControl1.Items;
    foreach(BaseLayoutItem item in items) {
        LayoutControlItem lci = item as LayoutControlItem;
        if(lci != null) {
            if (lci.TextVisible)
                lci.Control.AccessibleName = lci.Text;
        }
    }
}
vb
Imports DevExpress.XtraLayout

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim items As DevExpress.XtraLayout.Utils.ReadOnlyItemCollection = LayoutControl1.Items
    For Each item As BaseLayoutItem In items
        Dim lci As LayoutControlItem = TryCast(item, LayoutControlItem)
        If Not lci Is Nothing Then
            If (lci.TextVisible) Then
                lci.Control.AccessibleName = lci.Text
            End If
        End If
    Next item
End Sub

Example

The following example shows how to change a layout item’s control in code.

Assume that a DataLayoutControl is bound to a data source containing a Description field. The DataLayoutControl.RetrieveFields method retrieves information on available fields in the data source, and automatically creates layout items with controls for these fields. By default, for a field of the string type, a layout item with a TextEdit control inside it is created. The example shows how to locate a layout item with a control bound to the Description field, and replace its TextEdit control with a MemoEdit control. To change a layout item’s control, the new control must be assigned to the LayoutControlItem.Control property within the LayoutControl.BeginUpdate and LayoutControl.EndUpdate method pair.

csharp
using DevExpress.XtraLayout;
using DevExpress.XtraEditors;

dataLayoutControl1.RetrieveFields();

foreach (BaseLayoutItem baseItem in dataLayoutControl1.Items) {
    LayoutControlItem item = baseItem as LayoutControlItem;
    if(item !=null && item.Control.DataBindings.Count > 0)
        if (item.Control.DataBindings[0].BindingMemberInfo.BindingField == "Description") {
            dataLayoutControl1.BeginUpdate();
            Control prevControl = item.Control;
            Binding binding = prevControl.DataBindings[0];
            prevControl.DataBindings.Clear();
            dataLayoutControl1.Controls.Remove(prevControl);
            Control newControl = new MemoEdit();
            newControl.Name = "myMemoEdit";
            // Bind the new control to the same field as the previous control.
            newControl.DataBindings.Add(new Binding(binding.PropertyName, binding.DataSource,
                binding.BindingMemberInfo.BindingField, binding.FormattingEnabled));
            dataLayoutControl1.Controls.Add(newControl);
            item.Control = newControl;                        
            prevControl.Dispose();
            dataLayoutControl1.EndUpdate();
            // Change the item's size after the EndUpdate method.
            item.Size = new Size(100, 50);
            break;
        }
}
vb
Imports DevExpress.XtraLayout
Imports DevExpress.XtraEditors

dataLayoutControl1.RetrieveFields()

For Each baseItem As BaseLayoutItem In dataLayoutControl1.Items
    Dim item As LayoutControlItem = TryCast(baseItem, LayoutControlItem)
    If Not item Is Nothing AndAlso item.Control.DataBindings.Count > 0 Then
        If item.Control.DataBindings(0).BindingMemberInfo.BindingField = "Description" Then
            dataLayoutControl1.BeginUpdate()
            Dim prevControl As Control = item.Control
            Dim binding As Binding = prevControl.DataBindings(0)
            prevControl.DataBindings.Clear()
            dataLayoutControl1.Controls.Remove(prevControl)
            Dim newControl As Control = New MemoEdit()
            newControl.Name = "myMemoEdit"
            ' Bind the new control to the same field as the previous control.
            newControl.DataBindings.Add(New Binding(binding.PropertyName, binding.DataSource, _
                binding.BindingMemberInfo.BindingField, binding.FormattingEnabled))
            dataLayoutControl1.Controls.Add(newControl)
            item.Control = newControl
            prevControl.Dispose()
            dataLayoutControl1.EndUpdate()
            ' Change the item's size after the EndUpdate method.
            item.Size = New Size(100, 50)
            Exit For
        End If
    End If
Next baseItem

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Items property.

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.

connect-winforms-grid-to-backend-using-middletier-server/CS/WinForms.Client/EditForm.cs#L35

csharp
try {
    foreach(BaseLayoutItem layoutItem in dataLayoutControl1.Items) {
        if((layoutItem is LayoutControlItem layoutControlItem) && (layoutControlItem.Control != null)

See Also

HiddenItems

Creating Layout Items

LayoutControl Class

LayoutControl Members

DevExpress.XtraLayout Namespace