Propertygrid validation errors

11 posts, 0 answers
  1. Lakshmi
    Lakshmi avatar
    3 posts
    Member since:
    Dec 2013

    Posted 27 Dec 2013 Link to this post

    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.

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 31 Dec 2013 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Lakshmi
    Lakshmi avatar
    3 posts
    Member since:
    Dec 2013

    Posted 06 Jan 2014 Link to this post

    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.


  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 09 Jan 2014 Link to this post

    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 >>
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 09 Jan 2014 Link to this post

    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 >>
  7. Lakshmi
    Lakshmi avatar
    3 posts
    Member since:
    Dec 2013

    Posted 10 Jan 2014 Link to this post

    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.
  8. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 15 Jan 2014 Link to this post

    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 >>
  9. Gencebay
    Gencebay avatar
    1 posts
    Member since:
    Jul 2010

    Posted 14 Dec 2014 in reply to Dimitrina Link to this post

    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
  10. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 15 Dec 2014 Link to this post

    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.

     
  11. Gencebay
    Gencebay avatar
    3 posts
    Member since:
    Sep 2014

    Posted 17 Dec 2014 in reply to Dimitrina Link to this post

    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
  12. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 19 Dec 2014 Link to this post

    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.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready