DataLayoutControl Class
Creates and maintains a consistent layout of controls for editing a specific data source’s fields. See Data Layout Control.
Namespace: DevExpress.XtraDataLayout
Assembly: DevExpress.XtraLayout.v24.2.dll
NuGet Package: DevExpress.Win.Navigation
#Declaration
public class DataLayoutControl :
LayoutControl,
DataLayoutControlDesignerMethods
#Remarks
The DataLayoutControl extends the LayoutControl, providing an easy way to create a layout for editing a specific data source’s fields. It introduces design time tools - the Wizard and Data Source Binding Manager that can be activated via the control’s Tasks pane and Property Grid.
To learn more, see Data Layout Control.
#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.
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;
}
}