wpf-8834-controls-and-libraries-data-grid-grid-view-data-layout-columns-and-card-fields-applying-data-annotations.md
The GridControl supports multiple Data Annotation Attributes that are used for customizing data classes, to specify how data is displayed from a data source, define validation rules, and set relationships between data classes.
View Example: Apply Data Annotations
To use data annotation attributes, reference the System.ComponentModel.DataAnnotations assembly. To use additional attributes for setting masks, reference the DevExpress.Mvvm.v25.2 assembly.
Note
Non-string IEnumerable properties are not automatically populated. To generate editors for such properties, use the [Display(AutoGenerateField = true)] data annotation attribute.
Set the DataControlBase.EnableSmartColumnsGeneration property to true to enable the Smart Columns Generation.
Below is a list of the Smart Columns Generation features.
|
Data Field
|
Generated Column’s Settings
| | --- | --- | |
Numeric (nullable numeric) data type
|
TextEditSettings.MaskType = MaskType.Numeric;
| |
Boolean (nullable Boolean) data type
|
| |
Decimal
|
TextEditSettings.MaskType = MaskType.Simple;
TextEditSettings.Mask = ‘C’ ;
TextEditSettings.MaskPlaceHolder= ‘’;
| |
Enum data type
|
LookUpEditSettingsBase.ItemsSource = new EnumItemsSource ;
| |
DateTime (nullable DateTime) data type
or
[DataType(DataType.Date)] attribute
|
| |
Numeric data type
and
[DataType(DataType.PhoneNumber)] or [PhoneAttribute] attribute
|
TextEditSettings.MaskType = MaskType.Simple;
TextEditSettings.Mask = ‘(000) 000-0000’;
TextEditSettings.MaskUseAsDisplayFormat= true ;
| |
DateTime data type
and
[DataType(DataType.DateTime)] attribute
|
TextEditSettings.Mask = ‘g’ ;
TextEditSettings.MaskUseAsDisplayFormat= true ;
| |
DateTime data type
and
[DataType(DataType.Time)] attribute
|
TextEditSettings.Mask = ‘t’ ;
TextEditSettings.MaskUseAsDisplayFormat= true ;
| |
DateOnly data type
|
TextEditSettings.MaskType = MaskType.DateOnly;
TextEditSettings.Mask = ‘d’ ;
TextEditSettings.MaskUseAsDisplayFormat= true ;
| |
TimeOnly data type
|
TextEditSettings.MaskType = MaskType.TimeOnly;
TextEditSettings.Mask = ‘t’ ;
TextEditSettings.MaskUseAsDisplayFormat= true ;
| |
String data type
and
[DataType(DataType.MultilineText)] attribute
|
| |
String data type
and
[DataType(DataType.Password)] attribute
|
| |
[Url] attribute or [DataType(DataType.Url)]
|
| |
[DataType(DataType.ImageUrl)]
|
| |
[ReadOnly(true)] attribute
|
ColumnBase.ReadOnly = true ;
| |
[Editable(false)] attribute
|
ColumnBase.AllowEditing = false ;
| |
[Display(Order<0)] attribute
or
[HiddenAttribute] attribute
|
BaseColumn.Visible = false ;
| |
[Display(Description=DESCRIPTION)] attribute
|
BaseColumn.HeaderToolTip = ‘DESCRIPTION’ ;
| |
[Display(ShortName=NAME)] attribute
or
[Display(Name=NAME)] attribute
|
BaseColumn.Header = ‘NAME’ ;
| |
[Display(GroupName = “GROUPNAME”)] attribute
|
The column is placed into the GridControlBand.Columns collection of the band which BaseColumn.Name property is set to ‘GROUPNAME’.
|
In addition, the following attributes allow you to specify the editor’s mask settings: DateTimeMaskAttribute , NumericMaskAttribute , RegExMaskAttribute , RegularMaskAttribute , and SimpleMaskAttribute.
See Also
DevExpress MVVM Framework. Using DataAnnotation attributes and DevExpress Fluent API.