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

Intercept "Value cannot be converted" in code

6 Answers 184 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Ivan
Top achievements
Rank 1
Ivan asked on 06 Feb 2018, 09:22 AM

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?

6 Answers, 1 is accepted

Sort by
0
Ivan
Top achievements
Rank 1
answered on 08 Feb 2018, 09:32 AM
Anyone? I just need to check if RadPropertyGrid has any conversion errors/warnings
0
Vladimir Stoyanov
Telerik team
answered on 08 Feb 2018, 03:21 PM
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.
0
Ivan
Top achievements
Rank 1
answered on 12 Feb 2018, 06:06 AM

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.

0
Vladimir Stoyanov
Telerik team
answered on 14 Feb 2018, 05:07 PM
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.
0
Ivan
Top achievements
Rank 1
answered on 15 Feb 2018, 07:56 AM

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  ?

0
Vladimir Stoyanov
Telerik team
answered on 19 Feb 2018, 03:58 PM
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.
Tags
PropertyGrid
Asked by
Ivan
Top achievements
Rank 1
Answers by
Ivan
Top achievements
Rank 1
Vladimir Stoyanov
Telerik team
Share this question
or