Cannot bind to the property or column "Column Name" on the DataSource. Parameter name: dataMember

Viewed 5088

I have 2 DTO classes:

public class AddressDto
{
    public string Street { get; set; }
    public string City { get; set; }
    public string PostCode { get: set: }
}

public class CustomerDto
{
    public int Number{ get; set; }
    public string Name { get; set; }
    public AddressDto Address { get: set: }

    public CustomerDto() 
    {
        Address = new AddressDto();
    }
}

I have a form with a binding source in it that binds to CustomerDto. I also have a custom control with the address fields. This custom control has a binding source that binds to AddressDto The control's textboxes are correctly bound to the address properties.

The control exposes the following property:

[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
[Browsable(false)]
public object Address
{
    get { return bindingSource.DataSource; }
    set { bindingSource.DataSource = value; }
}

On one machine I do not get any errors on CheckBinding(). However on another machine I get the above exception when I try to open the form in runtime. In designtime everything works fine.

The control has 3 TextBoxes and the designer adds the following bindings:

this.bindingSource.AllowNew = true;
this.bindingSource.DataSource = typeof(AddressDto);

this.txtStreet.DataBindings.Add(new Binding("Text", this.bindingSource, "Street", true));
this.txtCity.DataBindings.Add(new Binding("Text", this.bindingSource, "City", true));
this.txtPostCode.DataBindings.Add(new Binding("Text", this.bindingSource, "PostCode", true));

Any ideas where the problem can be?

1 Answers
Related