【问题标题】:Cannot bind to the property or column States on the DataSource无法绑定到数据源上的属性或列状态
【发布时间】:2014-03-20 10:19:13
【问题描述】:

为什么会这样:

        public Form1()
    {
        InitializeComponent();
        exCheckedListBox1.DataSource = Profiles;
        this.exCheckedListBox1.DataBindings.Add(new System.Windows.Forms.Binding("Tag", this, "States", true));

    }

    CheckedBindingList Profiles = new CheckedBindingList();

    public int States
    {
        get
        {
            return Profiles.States;
        }
        set
        {
            Profiles.States = value;
        }
    }

}

public class CheckedBindingList : List<string>
{
    public int States { get; set; }
}

但是当绑定更改为

this.exCheckedListBox1.DataBindings.Add(new System.Windows.Forms.Binding("Tag", this.Profiles, "States", true));

抛出异常? 非常非常非常非常感谢。我尝试从继承表单 List 的自定义列表类中绑定文件。

异常 - 无法绑定到数据源上的属性或列状态。 参数名称:dataMember

【问题讨论】:

  • 如果您向我们展示例外情况,我们会有所帮助。

标签: winforms binding


【解决方案1】:

好像System.Windows.Forms.Binding参数dataSource不能是继承自List的类

这样就解决了问题:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        Load += new EventHandler(Form1_Load);
    }

    CheckedBindingList Profiles = new CheckedBindingList();
    SomeClass some_class = new SomeClass();

    public int States
    {
        get
        {
            return Profiles.States;
        }
        set
        {
            Profiles.States = value;
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        exCheckedListBox1.DataSource = Profiles;
        exCheckedListBox1.DataBindings.Add(new System.Windows.Forms.Binding("Tag", some_class, "States", true));
    }
}
public class CheckedBindingList : List<string>
{
    public int States { get; set; }
}
public class SomeClass
{
    public int States { get; set; }
}

【讨论】:

    猜你喜欢
    • 2021-04-09
    • 2012-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多