【发布时间】:2018-07-09 12:38:13
【问题描述】:
我有以下课程:
public class FunctionList : IEnumerable<Function> {
public string Comments {get; set;}
public IEnumerator<Function> GetEnumerator() {
return ...;
}
IEnumerator IEnumerable.GetEnumerator() {
return this.GetEnumerator();
}
}
这个类的一个对象被用作WinForm中Binding的数据源:
this.checkEdit1.DataBindings.Add(new Binding(nameof(this.checkEdit1.EditValue), functionList, nameof(functionList.Comments), false, DataSourceUpdateMode.OnPropertyChanged));
问题是,当dataSource (functionList) 实现IEnumerable<> 时,绑定不起作用。当我删除此接口时,它工作正常。否则我会得到以下ArgumentException:
Cannot bind to the property or column Comments on the DataSource.
Parameter name: dataMember
当dataSource 实现IEnumerable<> 时,我该怎么做才能使绑定工作?
【问题讨论】:
-
自定义
IEnumerable背后的任何原因,而不是使用许多内置类型之一,如List<T>? -
我需要在其他地方使用 IEnumerable-Interface 的对象。但在这种绑定场景下,它应该被忽略。