不能绑定到数据源的属性或列名。参数名称:数据成员 [英] Cannot bind to the property or column Name on the DataSource. Parameter name: dataMember

查看:507
本文介绍了不能绑定到数据源的属性或列名。参数名称:数据成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我收到的时候我试图绑定到System.Type.Name例外。

This is the exception that I'm getting when I'm trying to bind to a System.Type.Name.

下面是我在做什么:

this.propertyTypeBindingSource.DataSource = typeof(System.Type);

/* snip */

this.nameTextBox1.DataBindings.Add(
    new System.Windows.Forms.Binding(
        "Text", 
        this.propertyTypeBindingSource, 
        "Name", true));

有一些诀窍与结合的System.Type,这是不允许的,或有什么解决方法吗?有没有问题,结合其他类型的。

Is there some trick with binding to System.Type, is it not allowed or is there any workaround? Have no problems with binding to other types.

推荐答案

找到一个解决办法。做了一个类

Found a workaround. Made a class

public class StubPropertyType
{
    public StubPropertyType(Type type)
    {
        this.StubPropertyTypeName = type.Name;
    }

    public string StubPropertyTypeName = string.Empty;
}

创建了一个绑定源

created a binding source

this.propertyStubBindingSource.DataSource = typeof(StubPropertyType);

创建类的实例,并绑定的文本框了。

created an instance of the class and bound the textbox to it.

this.nameTextBox.DataBindings.Add(
    new System.Windows.Forms.Binding(
        "Text", 
        this.propertyStubBindingSource, 
        "StubPropertyTypeName", 
        true));

正好可以作为必需的。

works exactly as required.

这篇关于不能绑定到数据源的属性或列名。参数名称:数据成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆