Set property value when Delete key is pressed in PropertyGrid

I am currently working on a project that hosts the WinForms designer. I use a PropertyGrid to display the control properties of controls that are deleted on DesignSurface .

I created a UITypeEditor to change the values โ€‹โ€‹of my properties for user controls.

How can I reset the value of the null property when the Delete key is pressed in the PropertyGrid .

+4
source share
2 answers

This is handled in the PropertyDescriptor .

You override ResetValue and CanResetValue .

+2
source

Actually, all you have to do is add the attribute "DefaultValue" to the property and indicate that the default value is null.

Example:

 [DefaultValue(typeof(Image), null)] public Image MyLittlePicture { get; set; } 
+4
source

All Articles