[SOLVED] Set the Default Value for a Property Grid item

Answered
0
0

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 must to post comments
Best Answer
0
0

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.

  • You must to post comments
Great Answer
0
0

Hi Dmitry,

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!

 

Best,

Levie

  • You must to post comments
0
0

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.

  • You must to post comments
0
0

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.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.