【发布时间】:2015-02-26 13:16:52
【问题描述】:
我有这个模型:
public class CustomerType
{
public int Id {get; set;}
public string Name {get; set;}
public string Description {get; set;}
}
然后,我在 WinForms 表单上有一个绑定源,并通过执行以下操作将其绑定到现有对象:
var customerType = repository.Get(id);
bindingSource.DataSource = customerType;
我想清除数据源,所以我这样做:
bindingSource.DataSource = null;
但我得到以下异常:Cannot bind to the property or column Name on the DataSource.
将变量 customerType 设置为 null 不会清除数据源。
那么清除数据源的正确方法是什么?
【问题讨论】:
-
没有
bindingSource.Clear()吗? -
BindingSource 实现 IList 所以是的,有一个 bindingSource.CLear()
-
数据源只是一个 POCO 对象。
标签: c# winforms data-binding