Combobox绑定源

时间:2017-04-14 07:13:24

标签: c# combobox bindingsource

为什么此代码有效

// in a method
var query = a query;
    comboBox.DataSource = new BindingSource(query, null);   
    comboBox.DisplayMember = "Value";           
    comboBox.ValueMember = "Key";

但下面的代码不是

// in a class
public object DataSource
{
    set { comboBox.DataSource = value; }
}

// in a method
var query = a query;
    aclass.DataSource = new BindingSource(query, null);   
    aclass.DisplayMember = "Value";           
    aclass.ValueMember = "Key";

错误:"对象引用未设置为对象的实例。"

此代码也不起作用:

BindingSource bs = new BindingSource(query, null);
aclass.DataSource = bs;

0 个答案:

没有答案