Unplanned
Last Updated: 16 Feb 2024 12:27 by Martin
Martin
Created on: 10 Oct 2022 10:00
Category: UI for WinForms
Type: Feature Request
0
RadControls: Generic Valididation Mechanism for all controls

I would like to have a generic validation-mechanism, implemented in all controls. Hear me out:

A class ValidationInformation for containing all sort of validation information for a certain field, property, cell, etc. which has properties likes:

  • Type DataType
  • object MinValue
  • object MaxValue
  • int? MinLength
  • int? MaxLength
  • bool IsRequired
  • RegEx Mask
  • etc.

It also has a virtual method like bool Validate(object entity, object value, out string validationError).

A base class ValidationInformationProvider for retrieving validation information from various sources. It has some abstract methods for retrieval, storing/caching information per cell/field/property.

This base class has the following subclasses:

  • ValidationInformationProviderFromDataTable
  • ValidationInformationProviderFromAnnotations
  • ValidationInformationProviderFromXXX

Each provider is responsible for reading validation information from the source (DataTable, annotations on a property, etc.) and fill a ValidationInformation object.

Now the fun begins...

Each Telerik class, like RadGridView and/or subcomponents should get a method or event to retrieve ValidationInformation. When the event is not handled or the method returns null, the default behavior kicks in.

When ValidationInformation is provided, default behavior is overridden. Properties of editors van be set with values from ValidationInformation (like Minimum and Maximum of a GridViewDecimalColumnPlus or RadSpinEditorElement). At the end if editing the method ValidationInformation.Validate is called to validate the new value. The validation error can be used for popups, or tooltips, or an exception. 

This way a user does not have to think where to set which property of any Telerik control for any validation. This way a RadPropertyGrid and RadGridView can work the same way when it comes to data validation, regardless of all editors which work in the background. 

4 comments
Martin
Posted on: 16 Feb 2024 12:27

@erwin,

I party agree with you. The attributes in System.ComponentModel.DataAnnotations can be used used on an class you are in control of. But when you are using a class from a library, or simply use DataTable, then those attributes are useless. 

In that case it would be nice to implement a range of providers, one which can interpret DataAnnotations, one that can be implemented by user and provider information from another source, like metadata from a DataTable. All those providers provide the same object with (validation)information about the data to be displayed/edited/validated.

 

ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 29 Aug 2023 14:05

Hi, Erwin,

I believe that this is related to the other feature request you have on this topic:

https://feedback.telerik.com/winforms/1617352-radpropertygrid-should-honour-system-componentmodel-dataannotations-such-as-range 

I have associated the two feedback items so we will consider the possibilities when working on this case in future. The DataAnnotations attributes will be also researched.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

erwin
Posted on: 25 Aug 2023 11:18

I think a better Idea would be to fully support the standard .net validator attributes defined in System.ComponentModel.DataAnnotations for bound controls plus the .net Way of definining custom validation attributes (the later I'm not sure if it is already supported.

ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 12 Oct 2022 12:21

Hello, Martin,

Telerik UI for WinForms suite already offers RadValidationProvider which is a component that provides data validation management for editors in bound and unbound mode. It allows users to create various validation rules and associate them with editors derived from the RadEditorControl class. With RadValidationProvider users are not required to write any code for validation.

Please have a look at the following help article demonstrating how to get started with this component: https://docs.telerik.com/devtools/winforms/controls/validation-provider/getting-started 

Additional information about the different validation rules is available here: https://docs.telerik.com/devtools/winforms/controls/validation-provider/validation-rules 

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.