Hello everybody. I am trying to set the default value for a PropertyGrid using the DefaultValue attribute. Please tell me, can I use it or should I initialize the property at creation? Also, can I set minimum and maximum values for numeric properties?
You can turn of the expandable option, it’s all part of System.ComponentModel. Expandable objects have the ExpandableObjectConverter: https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.expandableobjectconverter?view=netframework-4.8
You can change the TypeConverter using the [TypeConverter] attribute and set the default one or your own custom one and even decide which child properties to show and in what order, etc… System.ComponentModel is a huge world in .NET and most of it is supported in Wisej.
It would make sense to use a backing field (see attached project).
I’ve also attached two ways to do the validation checking.
The first way is checking in the property setter.
The second way is using the IntegerValidator attribute (see attached).
Let me know if you have any other questions!
Thanks for your reply! If I understand correctly, we cannot turn off the plus or minus buttons. Like in the screenshot, but without the additional dropdown panel? I used a custom editor, which added a NumericUpDown control with the necessary settings.
I would recommend checking out the System.ComponentModel documentation: https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.defaultvalueattribute?view=netframework-4.8
It’s important to note that setting the DefaultValue attribute does not set the value of the property. It’s used in the designer for resetting the property to a default value and serialization.
Please login first to submit.