4

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.

Zuhaib
  • 1,420
  • 3
  • 18
  • 34

2 Answers2

4

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; }
Timothy Khouri
  • 31,315
  • 21
  • 88
  • 128
2

This is handled in the PropertyDescriptor.

You override ResetValue and CanResetValue.

leppie
  • 115,091
  • 17
  • 196
  • 297