[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Collapse]Form Layout Managers
    Side Panel
   [Collapse]Layout and Data Layout Controls
    [Expand]Product Information
    [Expand]Getting Started
    [Expand]Layout Control
    [Collapse]Data Layout Control
      Binding to Data Source in Code
      Displaying Nested Objects as Groups
      Data Annotation Attributes - Building Layout from Business Object
      Displaying Collection Properties
    [Expand]Layout Items
    [Expand]Layout Groups
    [Expand]Tabbed Groups
    [Expand]Other Layout Elements
    [Expand]Design-Time and Runtime Customization
    [Expand]Size and Alignment
     Flow Layout
     Table Layout
     Focus Management
    [Expand]Appearance and Look and Feel
    [Expand]Member Tables
   [Expand]Tabbed MDI Manager
    Tab Control
   [Expand]Wizard Control
    Workspace Manager
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Binding to Data Source in Code

The Data Layout Control can be bound to a data source in code with the DataLayoutControl.DataSource property. The following code demonstrates binding to a custom Address business object using the BindingSource component.

Note the DataLayoutControl.RetrieveFields method called after setting the DataLayoutControl.DataSource property. This method obtains information on available public properties in the bound data source and creates a layout item with an editor for each property.

Instead of manually calling the RetrieveFields method, you can enable the DataLayoutControl.AutoRetrieveFields property (which is disabled by default). With this property set to true, a layout is automatically re-built when a new data source is assigned to the DataLayoutControl.DataSource property.

By default, the Data Layout Control generates a linear vertical layout. Auto-generated editors embedded in layout items are bound to corresponding fields in the data source. The following sections show how to customize binding settings, editor types, layout items and editor options, and modify the layout.

Expanded Customize General Binding Settings and Layout Column Count

You can use a DataLayoutControl.RetrieveFields method overload to customize binding settings for all auto-generated editors and specify the layout column count.

The RetrieveFieldsParameters object provides the following parameters:


Gets or sets the default value used to initialize the Binding.DataSourceUpdateMode property for all auto-generated editors. This property indicates when changes to the bound editor property are propagated to the data source.


Gets or sets the default value used to initialize the Binding.DataSourceNullValue property for all auto-generated editors. This property identifies the value to be stored in the data source if the editor's value is null or empty.


Gets or sets the number of columns in the layout that will be generated.

To customize binding settings for individual layout items/editors, use the approach demonstrated in the following section.

Expanded Customize Individual Binding Settings, Editor Type and Visibility

When retrieving information on available public fields from the bound data source, the Data Layout Control fires the DataLayoutControl.FieldRetrieving event for each of these fields. This event fires before a layout item with an embedded editor is generated and thus it occurs prior to the editor's data binding. It allows you to customize the type of editor to be generated, modify editor binding settings and to hide certain editors (hidden layout items will be accessible at runtime from the Customization Form).

Expanded Customize Layout Item and Editor Settings

After a layout is created, the DataLayoutControl.FieldRetrieved event fires for each generated layout item. This event allows you to customize the settings of individual layout items and editors and to rearrange layout items.

Expanded Customize Layout Using Data Annotation Attributes

When binding to a business object, you can apply certain Data Annotation Attributes to the object's properties to give display names to layout items, specify the order of layout items, arrange items into groups and tabbed groups, specify the control's readonly status, assign masks to editors, etc. See the following topic for more information: Data Annotation Attributes - Building Layout from Business Object.

Expanded See Also

Is this topic helpful?​​​​​​​