我有2 DTO类:无法绑定到DataSource上的属性或列“列名称”。参数名称:数据成员
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();
}
}
我有在它结合CustomerDto
绑定源的形式。我也有地址栏的自定义控件。此自定义控件具有一个绑定源,该绑定源绑定到AddressDto
控件的文本框已正确绑定到地址属性。
控制公开以下属性:
[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
[Browsable(false)]
public object Address
{
get { return bindingSource.DataSource; }
set { bindingSource.DataSource = value; }
}
在一台机器,我不得到CheckBinding()
任何错误。但是,在另一台机器上,当我尝试在运行时打开表单时,出现上述异常。在设计时,一切正常。
控制有3 TextBoxes
和设计师增加了以下绑定:
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));
任何想法,问题出在哪里,可以吗?
你在绑定中使用属性路径吗?如果是的话,它可能类似于这个问题[绑定和多态 - 无法绑定属性或列(Winforms)](http://stackoverflow.com/questions/33789575/binding-and-polymorphism-cannot-bind-property-or -column-winforms/33790268#33790268) –
@IvanStoev号我没有使用属性路径。 –
如何提供某种[mcve] –