I'm currently populating the property grid using a RadPropertyStore. One of my object's properties is a nullable Int32 field (Int32?) and I need to allow the user to empty out the PropertyGridSpinEditor cell. Unfortunately, when the data cell is cleared out, it automatically gets set to a value of 0 instead of empty/null.
How can I allow the user to clear out the data and have null be considered a valid value?
PS. See attached screenshot for current behavior.
4 Answers, 1 is accepted
Thank you for writing.
PropertyGridSpinEditor expects a valid numeric value. When its value is cleared, 0 is set. In order to deal with this undesired behavior, you can use the ItemFormatting event and hide the text according to your criteria by setting the PropertyGridItemElement.ValueElement.DrawText property to false. Thus, 0 value will not be displayed:
An alternative solution is to implement a custom editor which will cover your requirement. Please refer to Using custom editor help article.
I hope this information helps. Should you have further questions I would be glad to help.
Thanks for the reply, Dess.
Unfortunately, just hiding the text won't be enough as I need to distinguish between the user typing in 0 and the user clearing the value (i.e. null).
I guess I'll have to look into a custom editor.
Thank you for writing back.
I have prepared a sample code snippet demonstrating how you can detect whether the value is cleared or the it is set to 0:
Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it in a way which suits your requirement best.
I hope this information helps. If you have any additional questions, please let me know.
Thank you very much for the example, Dess - it's really appreciated.
I'm actually doing something very similar to suit it to my needs.