We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Is it possible to validate prinulitelno cause specific cells for SfDataGrid

Hello.

I use SfDataGrid in my WPF application.
In this grid i have ComboBox column. And a set of mandatory fields is determined by value in this CommoBox. And row data save button i have in same row in other column, so row validation not be triggered in common case.

Question is:
Is it possible to force the validation call for specific cell? 


5 Replies

VL Vladimir September 3, 2015 03:32 PM UTC

Sorry errors in subject. I cant edit it now.


VL Vladimir September 4, 2015 07:39 PM UTC

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;
        }




ES Elangovan S Syncfusion Team September 7, 2015 06:58 AM UTC

Hi Vladimir,
 
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


VL Vladimir September 7, 2015 12:20 PM UTC

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?



ES Elangovan S Syncfusion Team September 8, 2015 09:47 AM UTC

Hi Vladimir,

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

Loader.
Live Chat Icon For mobile
Up arrow icon