Is it possible to validate prinulitelno cause specific cells for SfDataGrid
I found a solution.
I was hoping to do it with validation through Events, but i was wrong.
Suffice it to implement the INotifyDataError and use CustomValidadionAttribute.
(example: https://anthymecaillard.wordpress.com/2012/03/26/wpf-4-5-validation-asynchrone/)
Medot will look something like this
public static ValidationResult CustomValidate(object obj, ValidationContext context)
{
var itemObject = (ItemModel)context.ObjectInstance;
if (itemObject .Type == ItemType.Type1
&& !itemObject .Property1.HasValue)
{
return new ValidationResult(string.Format("Mandatory for type '{0}'", itemObject .Type .GetDescription()), new List<string> { "Property1" });
}
if (itemObject .Type != ItemType.Type1
&& itemObject .Property1.HasValue)
{
return new ValidationResult(string.Format("Not allowed for type '{0}'", itemObject .Type .GetDescription()), new List<string> { "Property1" });
}
return ValidationResult.Success;
}
Sorry for the delayed response,
Yes, it’s possible to validate the specific cell, by setting the GridValidationMode. GridValidationMode is the dependency property that switches between the modes of validations. The validation modes are as follows.
None: Disables the validations by Data Annotations and also by underlying Data implementations such as IDataErrorInfo or INotifyDataErrorInfo. By default, GridValidationMode is set to ‘None’.
InEdit: Enables the validations and displays the error information in the corresponding cell. You cannot shift the focus to other row.
InView: Enables the validations and displays the error information in the corresponding cell. Also, you can shift the focus to other cells to view the error information.
For more details, you can download the sample from the following location.
Sample:
http://www.syncfusion.com/downloads/support/forum/120138/ze/DataValidationDemo-349409116
UG Link:
http://docs.syncfusion.com/wpf/sfdatagrid/data-validation
Please let us know if you have any more query,
Regards,
Elangovan S
Thanks for your reply.
I have read the documentation before.
I was interested in revalidation of some fields by another field value changes.
And I was able to get it to implement INotifyDataErrorInfo.
But now I got another error. Could you help me with it?
I call revalidation for all properties in OnPropertyChanged, so i can be sure that all properties of model update error state. But the validation error in messages hint duplicated. Apparently, one takes by grid, the other is sent by property changed.
But with GridTemplateColumn it works fine, as with all other controls in which there is bounded to a properties with validation .
Is it possible to avoid duplication without replace column by GridTemplateColumn with standart controls in template?
And maybe i should create a separate topic for this issue?
Thanks for your update,
Could you please update the replication procedure or sample for revalidation? We cannot understand your replication procedure in which scenario your issue is reproducing for revalidation.
Regards,
Elangovan S
- 5 Replies
- 2 Participants
-
VL Vladimir
- Sep 3, 2015 03:30 PM UTC
- Sep 8, 2015 09:47 AM UTC