Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to automatically generate columns in the GridControl with required display format and masks using attributes and DevExpress Fluent API

$
0
0

This example demonstrates how to use the following attributes to influence columns generated by the GridControl:

-DisplayFormat

-NumericMask

-DateTimeMask

-RegExMask


You can also use the Fluent API mechanism instead of attributes. Create a class implementing the IMetadataProvider interface. In the IMetadataProvider.BuildMetadata method, assign required metadata:

[C#]
voidIMetadataProvider<Customer>.BuildMetadata(MetadataBuilder<Customer>builder){builder.Property(p=>p.ID).NumericMask("N0");builder.Property(p=>p.Name).DisplayFormatString("name is: {0}",true);builder.Property(p=>p.Phone).RegExMask(@"\d{2}-\d{2}-\d{2}");builder.Property(p=>p.HiredAt).DateTimeMask("dd/MM/yyyy");}

To register this metadata, use the following code:

[C#]
MetadataLocator.Default=MetadataLocator.Create().AddMetadata(typeof(Customer),typeof(DataAnnotationsElement1Metadata));

With this approach, you don't need to modify the model class code. This may be useful if you don't have access to this class code.


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>