Intercept "Value cannot be converted" in code

7 posts, 0 answers
  1. Ivan
    Ivan avatar
    4 posts
    Member since:
    Feb 2018

    Posted 06 Feb Link to this post

    Hi, I have RadPropertyGrid with auto generated property definitions. Some of the properties are numeric, and when something like letters is input in those properties, I get 'Value cannot be converted.." message.

    So this is a settings form, and I should be able to forbid saving those properties if such conversion issue exists, but how can I check that on code side?

  2. Ivan
    Ivan avatar
    4 posts
    Member since:
    Feb 2018

    Posted 08 Feb Link to this post

    Anyone? I just need to check if RadPropertyGrid has any conversion errors/warnings
  3. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    268 posts

    Posted 08 Feb Link to this post

    Hello Ivan,

    The 'Value cannot be converted.." message that you are observing is due to RadPropertyGrid's validation mechanism. For more information on the matter, you can take a look at the Validation article in our documentation and the Validation SDK example. Additionally you can use the Validation.Error attached event which is raised when a validation error is thrown. 

    I hope this helps. Let me know if you have any further questions.

    Regards,
    Vladimir Stoyanov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  4. Ivan
    Ivan avatar
    4 posts
    Member since:
    Feb 2018

    Posted 12 Feb in reply to Vladimir Stoyanov Link to this post

    Hi Vladimir,

    I have looked into telerik validation. The deal is that I don't have any validations assigned to my class. So I believe this "value cannot be converted" message comes from propertygrid.

  5. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    268 posts

    Posted 14 Feb Link to this post

    Hello Ivan,

    The validation message can also be shown if you are trying to enter a value that cannot be saved in the target property(for example if you are trying to enter a string into an integer field). What I can suggest in order to intercept that validation is to subscribe to the Validating event which is raised when you commit a PropertyGridField and RadPropertyGrid's EditMode is Single. I am attaching a sample project demonstrating this for your reference.  

    Regards,
    Vladimir Stoyanov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  6. Ivan
    Ivan avatar
    4 posts
    Member since:
    Feb 2018

    Posted 15 Feb in reply to Vladimir Stoyanov Link to this post

    Hi Vladimir,

    seems that approach works.

    But this makes some unwelcome changes in RadPropertyGrid looks -

    1. Instead of checkbox for bool fields we have text field with True/False

    2. Instead of description attribute of Enum it show string representation of it.

    Is it possible to address that, or it is the default behavior of RadPropertyGrid  ?

  7. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    268 posts

    Posted 19 Feb Link to this post

    Hello Ivan,

    This is the expected behavior. Since the EditMode is single, only one property can be edited at a time. All of the other properties are displayed in TextBlocks. You can read some more about that in the EditModes article in our documentation. 

    Regards,
    Vladimir Stoyanov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top