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

Propertygrid validation errors

10 Answers 250 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Lakshmi
Top achievements
Rank 1
Lakshmi asked on 27 Dec 2013, 12:47 PM

I have two issues:

1) On data type validation, I see the row highlight but do not see any error message as a comment that I see in DataAnnotations Support demo

2) How do I add validations like Required field validation or any custom validation at runtime.

I am using 2013.2.724.45 version of telerik controls.

10 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 31 Dec 2013, 01:03 PM
Hello,

As to your questions:
1. The declarative data annotation attributes (i.e. DisplayName) are only supported for auto-generated property definitions by design. Do you have the PropertyDefinitions autogenerated?
2. You can check this forum thread where a similar topic has been discussed.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Lakshmi
Top achievements
Rank 1
answered on 06 Jan 2014, 07:01 AM

Thank you for your response.

AutoGeneratePropertyDefinition is true and I am handling this event to assign grouping, display names and also override templates for few of the fields.

In the WPF telerik controls demo, I have seen even a message 'Value xxx could not be converted' when invalid data is entered. Looks like the telerik control internally handles the type conversion errors and throws this message.

In my case, only the Binding item is known at build all other attributes like display name, grouping, which fields are shown and all of the validations are known only at runtime. How can I add the validations dynamically at runtime. Any sample in this regard is highly appreciated.


0
Dimitrina
Telerik team
answered on 09 Jan 2014, 08:46 AM
Hello,

I have attached a sample solution to demonstrate the currently supported validation option. 

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Dimitrina
Telerik team
answered on 09 Jan 2014, 10:27 AM
Hello,

I have additionally extended the attached solution to also illustrate validation for Required fields.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Lakshmi
Top achievements
Rank 1
answered on 10 Jan 2014, 05:36 PM
Thanks for the sample. My requirement is to add the validations at runtime. Based on selection of few attributes in the form, required fields change.
0
Dimitrina
Telerik team
answered on 15 Jan 2014, 11:39 AM
Hello,

I am afraid you cannot change the [Required] Data Annotations attribute at runtime.
What you can do is to control this through validation extending the implementation of the IDataErrorInfo interface.
You will have to check the values of the additional criteria you have provided to be configured at runtime and then based on it validate a property as required or do not validate it at all. You can refer to the demo I sent on the implementation of the IDataErrorInfo interface.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Gencebay
Top achievements
Rank 1
answered on 14 Dec 2014, 08:18 PM
Hi,
The solution works for updated properties but we need manually trigger validation when submit - save button clicked!
Each item of PropertyDefinitions should trigger own validation rule(s) without updated source!
How can we do it like this way!
Thanks
0
Dimitrina
Telerik team
answered on 15 Dec 2014, 11:15 AM
Hi,

I am afraid this would not be possible for the time being, what I can suggest you is the approach explained below.

Regards,
Dimitrina
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
Gencebay
Top achievements
Rank 1
answered on 17 Dec 2014, 03:47 PM
public ConfiguredTemplate GetConfigureTemplate(EAVPropertyAndValue item)
        {
            FrameworkElementFactory elmFactory = new FrameworkElementFactory();
            DataTemplate dataTemplate = new DataTemplate();
            Binding propBinding = new Binding
            {
                Mode = BindingMode.TwoWay,
                Source = item,
                Path = new PropertyPath("PropertyValue")
            };
 
            bool IsRequired = item.EAVPropertyDefinations.IsRequired;
            if (IsRequired)
            {
                propBinding.NotifyOnValidationError = true;
                propBinding.ValidatesOnDataErrors = true;
                propBinding.ValidatesOnExceptions = true;
                propBinding.ValidationRules.Add(new PropertyRequiredValidator(item.PropertyDefinations.ValidationMessage));
                if (!string.IsNullOrWhiteSpace(item.PropertyDefinations.ValidationRegex))
                {
                    propBinding.ValidationRules.Add(new RegexValidationRule(item.PropertyDefinations.ValidationRegex, item.PropertyDefinations.ValidationMessage));
                }
            }
 
            switch (_metaDataType)
            {
                case MetaDataType.String:
                    elmFactory.Type = typeof(TextBox);
                    elmFactory.SetBinding(TextBox.TextProperty, propBinding);
                    dataTemplate.VisualTree = elmFactory;
                    break;
                case MetaDataType.Date:
                    elmFactory.Type = typeof(RadDateTimePicker);
                    elmFactory.SetValue(RadDateTimePicker.InputModeProperty, InputMode.DatePicker);
                    elmFactory.SetBinding(RadDateTimePicker.SelectedValueProperty, propBinding);
                    dataTemplate.VisualTree = elmFactory;
                    break;
                case MetaDataType.GenericCode:
                    JToken o = JObject.Parse(item.PropertyDefinations.MetaDataSettings);
                    if (o[MetaDataSettings.GenericCodeTypeId] != null)
                    {
                        long id = o[MetaDataSettings.GenericCodeTypeId].Value<long>();
                        var genericCodeType = CacheHelperFunctions.GetAllGenericCodeTypes().Where(c => c.ID == id).FirstOrDefault();
                        var lookups = CacheHelperFunctions.GetAllGenericLookups().Where(x => x.GenericCodeTypeID == id).Select(x => x).ToList();
                        var itemSource = new GenericLookupsComposite
                        {
                            GenericCodeTypeDefinition = genericCodeType.Definition,
                            GenericCodeTypeId = genericCodeType.ID,
                            IdNamePairs = lookups.Select(n => new IdNamePair { ID = n.ID, Name = n.OptionName }).ToList()
                        };
 
                        Binding sourceBinding = new Binding();
                        sourceBinding.Source = itemSource;
                        sourceBinding.Mode = BindingMode.TwoWay;
                        sourceBinding.Path = new PropertyPath("IdNamePairs");
 
                        Binding combopropBinding = new Binding
                        {
                            Mode = BindingMode.TwoWay,
                            Source = item,
                            Path = new PropertyPath("PropertyDataValueKeyId"),
                            UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                        };
 
                        elmFactory.Type = typeof(RadComboBox);
                        elmFactory.SetBinding(RadComboBox.ItemsSourceProperty, sourceBinding);
                        elmFactory.SetValue(RadComboBox.DisplayMemberPathProperty, "Name");
                        elmFactory.SetValue(RadComboBox.SelectedValuePathProperty, "ID");
                        elmFactory.SetValue(RadComboBox.TextProperty, propBinding);
                        elmFactory.SetBinding(RadComboBox.SelectedValueProperty, combopropBinding);
                        dataTemplate.VisualTree = elmFactory;
                    }
                    break;
                default:
                    break;
            }
 
            dataTemplate.Seal();
            return new ConfiguredTemplate { DataTemplate = dataTemplate, PropertyBinding = propBinding };
        }

Above code provides EditorTemplate and Dynamic Binding for Telerik WPF PropertyGrid control. We are trying trigger validation for all propertygrid fields to fill with global Validation.ErrorEvent to the ValidationResult list. 
Can we use binding expressions like this or any suggest!?
http://stackoverflow.com/questions/5676202/how-to-force-a-wpf-binding-to-refresh this link sugges
0
Dimitrina
Telerik team
answered on 19 Dec 2014, 11:36 AM
Hello,

You can try using validator.ValidateObject. That way the validation on the bindings will not be raised. Still, if there are validation errors, you can gather them and show them like a validation summary.

Regards,
Dimitrina
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
PropertyGrid
Asked by
Lakshmi
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Lakshmi
Top achievements
Rank 1
Gencebay
Top achievements
Rank 1
Gencebay
Top achievements
Rank 1
Share this question
or