Set Value of Property When Delete Key is Pressed in PropertyGrid

1.5k Views Asked by At

I am currently working on a project that hosts WinForms designer. I am using PropertyGrid to display manipulate properties of the controls that are dropped on the DesignSurface.

I have created UITypeEditor's to modify values of my custom controls properties.

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

2

There are 2 best solutions below

1
leppie On BEST ANSWER

This is handled in the PropertyDescriptor.

You override ResetValue and CanResetValue.

1
Timothy Khouri On

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

Example:

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