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
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
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.
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
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 ?
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