StrataFrame Forum

Changing the value of a custom property programmatically, does not update the control.

http://forum.strataframe.net/Topic13763.aspx

By George Nentidis - 1/28/2008

Hi there.

I have a string custom property in a BO which I bind to a MicroFour.StrataFrame.UI.Windows.Forms.DevEx.TextEdit.

When setting the value of the property at run-time, with code 

Customer.CustomProperty = "SomeValue";

the control does not show the changed value. Is it something I'm not doing right? BindingUpdateMode and ControlSourceUpdateMode are both OnPropertyChanged.

I have tried this with your DevEx sample application, and does not work there either.

By Trent L. Taylor - 1/28/2008

There are several options here, but the reason is that there is not a native Changed event managing the custom property.  However, you can do several things, you can create a custom event (propnameChanged as EventHandler) that is raised when the value is changed....or just call the Refresh method on the BO:

Customers.Refresh("MyCustomFieldName")

or within the property

Me.Refresh("MyCustomFieldName")
By StrataFrame Team - 1/28/2008

If the custom property does not have a backing field within the underlying DataTable, you will need to raise a "Changed" event when the property is set.  The event needs to be an EventHandler and needs to be named PropertyNameChanged where "PropertyName" is the name of your property (i.e. TextChanged on a textbox).  The .NET binding system will then find the event and add a handler to it to determine when to refresh the control.  So:

public event EventHandler CustomPropertyChanged;

protected virtual void OnCustomPropertyChanged(EventArgs e)
{
    if (CustomPropertyChanged != null)
    { CustomPropertyChanged(e); }
}

[all of the necessary attributes]
public string CustomProperty
{
    get { return _customProperty; }
    set
    {
        if (_customProperty != value)
        {
            _customProperty = value;
            OnCustomPropertyChanged(EventArgs.Empty);
        }
    }
}

By George Nentidis - 1/29/2008

Thank you guys.

It's really nice knowing I can count on you...

By StrataFrame Team - 1/29/2008

We help where we can Smile