mrvinent
mrvinent

Reputation: 125

XAF - Changing value of a PropertyEditor

I'm learning XAF and I want to know how to access the value of a PropertyEditor to change it. I want to take the value from a PropertyEditor and put that value into another PropertyEditor's value. My code is like this:

Property Editor reserva = (PropertyEditor)((DetailView)View).FindItem("Reserva"); //This is a custom object
PropertyEditor dni = (PropertyEditor)((DetailView)View).FindItem("Dni");//This is a simple text editor
PropertyEditor dniReserva = (PropertyEditor)reserva.View.FindItem("Dni");//This is a variable from the custom object
dni.PropertyValue = dniReserva.ControlValue;

This does not work, any ideas? Thank you

Upvotes: 0

Views: 2878

Answers (2)

Uranus
Uranus

Reputation: 1690

Each property editor in XAF reads value from the specific property of the business object. This specificity reduces your task to copying the value of the specific property to another one.

In the ViewController, you can access the current business object using the View.CurrentObject property. Once the property is updated with an appropriate value, the new value will immediately appear in the property editor.

If the business object does not implement the INotifyPropertyChanged interface (for example, if you are using Entity Framework Code First), you may also want to call the View.Refresh method to make new values appear in the editor.

Upvotes: 1

yiannis
yiannis

Reputation: 430

Are you talking about copying the value of a non persistent property to another non persistent property? Because in any other case I believe there are more suitable ways to copy a value, working with the actual properties (here is usefull answer to help you with that)and not the editors. If however you actually need this,I believe you could create a ViewController and use the PropertyEditor properties like this

        foreach (PropertyEditor editor in ((DetailView)View).GetItems<PropertyEditor>())
        {
            var control = editor.Control as IntegerEdit;
            if (control != null)
            {
                    if (editor.Id == "Id" || editor.Caption == "Id")
                    {
                        control.Enabled = false;
                    }           
            }
        }

Upvotes: 2

Related Questions