How to: Bind a Standalone Editor in Code

To bind a standalone editor in code, you need to add a Binding object to the control's DataBindings collection. The FormattingEnabled property must be set to true.

The following example shows how to bind a DateEdit control to a nullable property of an Entity business object.


// An Entity object.
Entity _entity = new Entity();
// Bind the editor to the Entity.NullableDateTime property. 
// Set the Binding.FormattingEnabled property to true.
dateEdit1.DataBindings.Add("EditValue", _entity, "NullableDateTime", true);

public class Entity {
    public Entity() { }

    private DateTime? _nullableDateTime = new DateTime(2001, 1, 1);

    public DateTime? NullableDateTime {
        get { return _nullableDateTime; }
        set { _nullableDateTime = value; }
    }
}