Force property grid to update after ResetValue in PropertyDescriptor

时间:2015-07-28 22:51:24

标签: c# winforms propertydescriptor icustomtypedescriptor

I am using the property grid in winforms to display the properties on my custom type - I did this using a custom type descriptor (implementing interface ICustomTypeDescriptor) so that the public properties of my object are displayed, each with their own PropertyDescriptor implementation.

The implementation is close to the code described here: http://www.codeproject.com/Articles/4448/Customized-display-of-collection-data-in-a-Propert

This works as in I can see all the properties and they have their own editors in the property grid however I have the problem on how to implement

public override void ResetValue(object component)

On the base PropertyDescriptor.

At the moment I have implemented it like this:

public override void ResetValue(object component)
{
    if (!_isReadOnly && _dataDefault != null)
    {
        SetValue(component, _dataDefault.Value);
    }
}

However, althogh the data does indeed get updated the property grid display just show the old value unless I refresh it - I can't figure out how the property grid would update or get to know a value has changed, is there some sort of event that refreshes that cell that can be triggered from a PropertyDescriptor implementation?

1 个答案:

答案 0 :(得分:0)

我在这里找到了类似的问题:PropertyGrid doesn't notice properties changed in code?

我采用的解决方案是实现INotifyPropertyChanged通知事件并将其注册到属性网格上进行刷新。