Hi, sorry for delay in Reply.. I analyzed further and found the following:
The resetButton is enabled now by calling the OverParam method. The CanResetValue is overridden from PropertyDescriptor class. In the propertyItem the overridden ResetValue value method sets the value to defaultValue which is evident and can be seen but the change won't be reflected in the PropertyGrid UI. We also called the PropertyService_ResetPropertyEventHandler to ensure it notifies but still no luck. Sharing code:
private void PropertyService_ResetPropertyEventHandler(object sender, EventArgs e)
{
string fullPath = null;
if (sender is PropertyClass property)
{
fullPath = GetFullname(property);
OnGridPropertyChanged(property.Name,property.Value,fullPath);
}
else if(sender is ComplexPropertyClass Comproperty)
{
fullPath = Comproperty.Name;
OnGridPropertyChanged(Comproperty.Name, Comproperty.Value, fullPath);
}
}
public override void ResetValue(object component)
{
if (CanResetValue(component))
{
property.ResetValue();
if (property is PropertyClass props && !string.IsNullOrEmpty(props.Validation) && !props.Value.Equals(props.DefaultValue))
{
var instance = GetInstanceFromAssembly<ICustomPropertyValidation>(props.Validation);
if (instance is ICustomPropertyValidation customPropertyDialog)
{
if (customPropertyDialog.CanChangeValue(null, property.Value, true))
{
UpdateReset();
}
}
return;
}
else
{
UpdateReset();
}
}
}
private void UpdateReset()
{
property.ResetValue();
var serviceProvider = ServiceProvider.GetService(typeof(IDevicePropertiesService));
if (serviceProvider is IDevicePropertiesService Service)
{
Service.ResetProperyOnValueChanged(property, new EventArgs());
}
}
public override void ResetValue()
{
Property.ResetValue();
}
internal void ResetValue()
{
SetValue(DefaultValue);
IsOverparam = false;
}
public void SetValue(string value)
{
if (value != this.valueField)
{
this.Value = value;
this.ModifiedTime = DateTime.Now.ToString(System.Globalization.CultureInfo.InvariantCulture);
}
}
The Logic for determining is ResetButton can be enabled is following:
public override void Overparam(NamedProperty namedProperty, bool setOverparamFlag, string currentProfile = "")
{
if (namedProperty is ComplexProperty)
{
//If this property has an associated ProfileProperty, set its attributes and Value (if necessary, and as an override(bold))
if (Profile != null && setOverparamFlag == false)
{
Profile.Overparam(setOverparamFlag, currentProfile, this);
}
this.Overparam(((ComplexProperty) namedProperty).Items, setOverparamFlag, currentProfile);
}
}
Please provide further assistance.
[Modified 2 years ago]