This is a migrated thread and some comments may be shown as answers.

Custom ValidationResult

3 Answers 141 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marcel
Top achievements
Rank 1
Iron
Marcel asked on 06 Nov 2014, 10:33 AM
Hi there,

I'm developing a view for a model which makes use of DataAnnotation validation. The RadGridView is automatically showing the error messages triggered by invalid input. But, the model's validators are returning a custom implementation derived from System.ComponentModel.DataAnnotations.ValidationResult which contains additional properties. I need to somehow bind those additional properties in the view (e.g. in the GridViewEditorPresenter) but it seems like the RadGridView is transforming the ValidationResult to some Telerik specific class (GridViewCellValidationResult) and of course the additional information gets lost. Is there an easy way (or maybe a work-around) to somehow access the original ValidationResult in the GridViewCellValidationResult-Template?

Regards,
Marcel

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 10 Nov 2014, 11:18 AM
Hello Marcel,

Indeed, you are right. We wrap all validation errors in GridViewCellValidationResult. What is the information that you want to have that we hide ? What is the exact scenario that you want to accomplish ? 


Regards,
Maya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Marcel
Top achievements
Rank 1
Iron
answered on 09 Dec 2014, 08:13 AM
Hi Maya,

I need to somehow transfer more information from the validator in the model to the GridViewEditorPresenter template in the view. My first approach was to inherit ValidationResult and add some properties there. This would be for example a "Priority" property which should somehow express the importance level of the validation error (e.g. yellow/orange/red etc.). I need more than just valid/not valid plus error message. Because of the transformation from .NET's ValidationResult to Telerik's GridViewCellValidationResult, this approach was a dead end.  

My next thought was to somehow get hold of the ValidationContext (or the validated object instance) inside the GridViewEditorPresenter, but it does not seem to be anywhere in the DataContext. So I can't find a way to connect the ValidationResult to the validated value/property in any way inside the GridViewEditorPresenter. Maybe this is just no valid use case for the build-in validation mechanism with data annotations and I need to use a totally different approach…

Regards,
Marcel
0
Maya
Telerik team
answered on 09 Dec 2014, 09:46 AM
Hi Marcel,

I am afraid that if you want to customize the validation in a way, you would better follow some of the approaches that give a bit more freedom. For example, implementing IDataErrorInfo/ INotifyDataError, handling validating events of RadGridView. 
Check out "Validating"article (and the links towards our SDK examples at the end) for a reference. 

Regards,
Maya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Marcel
Top achievements
Rank 1
Iron
Answers by
Maya
Telerik team
Marcel
Top achievements
Rank 1
Iron
Share this question
or