Format datagrid columns by DataAnnotations

Hello,

My Model class has dataannotation attributes, for example:

        [DataMember]

        [Display(Name = "Jel mező")]

        [StringLength(20, MinimumLength = 7, ErrorMessage = "Minimum {2}, maximum {1} karakter hosszú lehet!")]

        [StartsWithValidation("ss")]

        [Required(ErrorMessage = "A mező kitöltése kötelező!")]

        public string Jel { get; set; }

As described at the below url: the original DataGrid control can be formatted and set properties by the attribute values of the model property, for example, set HeaderText, Tooltip, Order, Readonly, Visibled etc...

https://stackoverflow.com/questions/32015348/dataannotations-support-in-windows-forms

Also the validation can be automatic:

https://www.reza-aghaei.com/dataannotations-validation-attributes-in-windows-forms/

Do you have any similar built-in solution with SfDataGrid?

If no, can this a feature request for the future?

With a similar function a manual work to setup the SfDataGrid (and the validation) will be automatic and the developing time would be much-more faster.

Thank you!


3 Replies 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team July 6, 2022 04:21 PM UTC

Hi SZL,

SfDataGrid support to generate the columns based on built-in Data Annotation Attributes. For more information related to DataAnnotations, please refer to the below user guide documentation link,


UG Link:
 https://help.syncfusion.com/windowsforms/datagrid/columns#data-annotations-with-autogeneratecolumns

And the SfDataGrid allows to validate the data using data annotation attributes by setting SfDataGrid.ValidationMode or GridColumn.ValidationMode property to InEdit or InView.

UG link: https://help.syncfusion.com/windowsforms/datagrid/datavalidation#using-data-annotation

Please have a look at this and revert us if you need any further assistance for this.

Regards,
Vijayarasan S.


Marked as answer

SZ SZL replied to Vijayarasan Sivanandham July 11, 2022 11:23 AM UTC

Thank you very much, its perfect!



VS Vijayarasan Sivanandham Syncfusion Team July 12, 2022 05:53 AM UTC

Hi SZL,

If you are satisfied with our response, please mark it as an answer. Otherwise, please let us know if you have any further queries on this. We are happy to help you.

Regards,

Vijayarasan S


Loader.
Up arrow icon