[Expand]General Information
[Collapse]WinForms Controls
 [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]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 Item
    [Expand]Layout Groups
    [Expand]Tabbed Group
    [Expand]Other Layout Elements
    [Expand]Customization Capabilities
    [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]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Data Annotation Attributes - Building Layout from Business Object

The Data Layout Control recognizes specific Data Annotation attributes applied to a bound business object's properties. When building a layout, the Data Layout Control uses these attributes 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.


  • To use Data Annotation attributes, ensure that the System.ComponentModel.DataAnnotations assembly is added to your project.
  • If your data source is a custom object decorated with attributes and this object is not an IEnumerable collection, do not pass it to the control's DataLayoutControl.DataSource property directly. Instead, use the BindingSource component. Otherwise, data annotation attributes will not be parsed correctly.

Expanded Online Video

Consider the following MyClassTabsLayout business object, which contains multiple fields with no attributes applied. When this object is bound to a Data Layout Control, a linear layout is generated, as follows.

Code Data Layout Control

To combine items in groups, specify item order, assign custom captions, set masks for editors, etc., certain Data Annotation attributes can be applied to the object's fields. In the following code, Data Annotation attributes are applied to fields of the same business object. The Data Layout Control takes into account these attributes when generating a layout.

Code Data Layout Control

Expanded Layout Generation Attributes

The table below covers attributes that allow you to specify an item's visibility, label, hint, read-only state and display format. Certain attributes are used to position items in regular and tabbed groups.

Attribute Attribute's Parameter Description
System.ComponentModel.DataAnnotations.DisplayAttribute GroupName

This parameter allows you to place a generated layout item into a group or tabbed group. If the parameter refers to a non-existing group, it will be automatically created.

Created Group Type

To specify the type of the created group, enclose the group name with the following characters.

Group Item Orientation

You can specify the orientation of items within the created group by appending "|" and "-" characters to a group name. These specify the vertical and horizontal orientations of items respectively.

If the orientation is not specified using these characters, items are arranged vertically in this group. The orientation of items within the root group (the DataLayoutControl itself) is always vertical.

Nested Groups

To place a layout item into a group that is nested in another group, the GroupName parameter must specify the full path to the target group (including all parent groups). Group names should be delimited using the "/" character in the full path.

Name If specified, this parameter defines a label for the generated layout item. If the parameter is omitted, the layout item's label is specified by the property's name. You can set the parameter to an empty string to hide the layout item's label.
ShortName The same as the Name parameter.
Description Assigns a tooltip to the generated layout item.
Order Specifies the order of the layout item among other layout items. If this attribute parameter is omitted, the layout item is pushed to the bottom of its parent group.
AutoGenerateField Specifies whether or not a layout item (with a control) is automatically generated for the current field.
System.ComponentModel.ReadOnlyAttribute - Specifies whether this generated editor is in read-only mode.
System.ComponentModel.DataAnnotations.DisplayFormatAttribute DataFormatString Specifies the display format for the generated editor.
ApplyFormatInEditMode Specifies whether the editor's display format must also apply in edit mode.

Expanded Editor Type and Settings Attributes

The type of editors used to edit the bound object's properties can be specified using the System.ComponentModel.DataAnnotations.DataTypeAttribute, System.ComponentModel.DataAnnotations.EnumDataTypeAttribute and System.ComponentModel.DataAnnotations.MetadataTypeAttribute.

DataTypeAttribute Attribute parameter Created editor
DataType.Date DateEdit
DataType.DateTime DateEdit
DataType.Duration TimeSpanEdit
DataType.Time TimeEdit
DataType.Text TextEdit
DataType.MultilineText MemoEdit
DataType.Password TextEdit with password input enabled
(see RepositoryItemTextEdit.UseSystemPasswordChar).
DataType.Url TextEdit
DataType.Currency TextEdit with the numeric currency mask ("c").
DataType.Html TextEdit
EnumDataTypeAttribute Description
Allows you to replace numeric enumerator values with corresponding declarations.
MetadataTypeAttribute Description
Allows you to derive data annotation attributes from another class.

Expanded Validation Attributes

Attribute Editor
System.ComponentModel.DataAnnotations.StringLengthAttribute Specifies the maximum and minimum number of characters for string records within the editor.
System.ComponentModel.DataAnnotations.RangeAttribute A numeric value should lie in a specific range, set by using this attribute.
System.ComponentModel.DataAnnotations.RequiredAttribute Shows an error icon if an end-user is about to leave a modified editor when the edit value is null or an empty string.
System.ComponentModel.DataAnnotations.CompareAttribute Compares the editor's value with another property. The entering of values that differ from the compared property's value is restricted.

Expanded See Also

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