- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试将 TextBox
的 Text
属性绑定(bind)到 DataSet
的 DataSetName
属性。
我明白了
System.ArgumentException: 'Cannot bind to the property or column DataSetName on the DataSource. Parameter name: dataMember'
有没有办法这样绑定(bind)单个文本框?我认为这与 DataSet
是一个集合这一事实有关,因此 BindingSource
期望绑定(bind)一个表,而不是文本框。
我能否在不创建“容器”类来保存我的 DataSetName
属性和 DataSet
的情况下实现这一目标?
编辑
不包含任何代码对我来说很愚蠢。所以给你:
this.tableGroupBindingSource.DataSource = typeof(DataSet);
...
this.TableGroupNameTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.tableGroupBindingSource, "DataSetName", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
...
tableGroupBindingSource.DataSource = node.TableGroup;
node.TableGroup
正确(不为空,指向右上DataSet
)一旦实际绘制了 TextBox
,就会出现上述异常。
我在设计器中使用 Windows 窗体,因此前两行代码是自动生成的。
最佳答案
CurrencyManager
使用 ListBindingHelper.GetListItemProperties(yourDataset)
来获取它的属性,由于它的类型描述符不返回任何属性,因此数据绑定(bind)失败。
您可以通过使用数据集包装器以不同的方式公开 DataSet
属性,实现自定义类型描述符以提供数据集属性:
using System;
using System.ComponentModel;
public class CustomObjectWrapper : CustomTypeDescriptor
{
public object WrappedObject { get; private set; }
public CustomObjectWrapper(object o) : base()
{
WrappedObject = o ?? throw new ArgumentNullException(nameof(o));
}
public override PropertyDescriptorCollection GetProperties()
{
return this.GetProperties(new Attribute[] { });
}
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
return TypeDescriptor.GetProperties(WrappedObject, true);
}
public override object GetPropertyOwner(PropertyDescriptor pd)
{
return WrappedObject;
}
}
然后这样使用:
var myDataSet = new DataSet("myDataSet");
var wrapper = new CustomObjectWrapper(myDataSet);
textBox1.DataBindings.Add("Text", wrapper, "DataSetName", true,
DataSourceUpdateMode.OnPropertyChanged);
关于c# - 将 TextBox.Text 绑定(bind)到 DataSet.DataSetName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51865693/
我在我的报告中添加了一个额外的新数据集,从那以后就一直收到这个神秘的错误。 最佳答案 问题是,当报告使用我在创建报告时定义的第一个数据集设置元素时。添加额外的数据集将 DataSetName 值重置为
由于某些奇怪的原因,我无法运行我的报告,当我尝试预览时,我收到此错误: 这是我的 tablix 属性的样子: 知道该怎么做吗?当前的 .rdl 是从另一个 .rdl 复制的。我更改了新复制的 .rdl
我正在尝试将 TextBox 的 Text 属性绑定(bind)到 DataSet 的 DataSetName 属性。 我明白了 System.ArgumentException: 'Cannot b
我是一名优秀的程序员,十分优秀!