【发布时间】:2020-10-10 00:25:59
【问题描述】:
我有以下代码应该在我的 windows 窗体中的两个文本框上实现数据绑定:
private void GetData()
{
bindingSourceStudies.DataSource = StudysTable;
bindingSourceStudies.DataMember = "ID";
txtName.DataBindings.Add(new Binding("Text", bindingSourceStudies, "Name")); //#ERROR
txtClass.DataBindings.Add("Text", bindingSourceStudies, "Class");
}
但是,当我运行它时,它在指示行失败并显示错误消息:
Cannot bind to the property or column Name on the DataSource.
Parameter name: dataMember
我知道这个网站上有很多关于这个特定错误的问题,但是,大多数问题,例如this one 说指定的列不存在或拼写错误。但正如您在下面看到的那样,名为 "Name" 的列显然存在于 BindingSource 中,并且似乎拼写正确。
我已经尝试过使用和不使用new Binding(...) 语法,但无论哪种方式都失败了。显然我错过了什么,我在这里做错了什么?
【问题讨论】:
标签: c# data-binding .net-4.5 bindingsource