Skip to main content

Applying Data Annotations

  • 2 minutes to read

Overview

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.v24.1 assembly.

Note

Non-string IEnumerable properties are not automatically populated. To generate editors for such properties, use the [Display(AutoGenerateField = true)] data annotation attribute.

Smart Columns Generation

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

 TextEditSettings.MaskType = MaskType.Numeric;

Boolean (nullable Boolean) data type

CheckEditSettings

Decimal

TextEditSettings

 TextEditSettings.MaskType = MaskType.Simple;

 TextEditSettings.Mask = ‘C’;

 TextEditSettings.MaskPlaceHolder= ‘’;

Enum data type

ComboBoxEditSettings

 LookUpEditSettingsBase.ItemsSource = new EnumItemsSource;

DateTime (nullable DateTime) data type

or

[DataType(DataType.Date)] attribute

DateEditSettings

Numeric data type

and

[DataType(DataType.PhoneNumber)] or [PhoneAttribute] attribute

TextEditSettings

 TextEditSettings.MaskType = MaskType.Simple;

 TextEditSettings.Mask = ‘(000) 000-0000’;

 TextEditSettings.MaskUseAsDisplayFormat= true;

DateTime data type

and

[DataType(DataType.DateTime)] attribute

DateEditSettings

 TextEditSettings.Mask = ‘g’;

 TextEditSettings.MaskUseAsDisplayFormat= true;

DateTime data type

and

[DataType(DataType.Time)] attribute

DateEditSettings

 TextEditSettings.Mask = ‘t’;

 TextEditSettings.MaskUseAsDisplayFormat= true;

DateOnly data type

TextEditSettings

TextEditSettings.MaskType = MaskType.DateOnly;

TextEditSettings.Mask = ‘d’;

TextEditSettings.MaskUseAsDisplayFormat= true;

TimeOnly data type

TextEditSettings

TextEditSettings.MaskType = MaskType.TimeOnly;

TextEditSettings.Mask = ‘t’;

TextEditSettings.MaskUseAsDisplayFormat= true;

String data type

and

[DataType(DataType.MultilineText)] attribute

MemoEditSettings

String data type

and

[DataType(DataType.Password)] attribute

PasswordBoxEditSettings

[Url] attribute or [DataType(DataType.Url)]

HyperlinkEditSettings

[DataType(DataType.ImageUrl)]

PopupImageEditSettings

[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