Why this code works
// in a method
var query = a query;
comboBox.DataSource = new BindingSource(query, null);
comboBox.DisplayMember = "Value";
comboBox.ValueMember = "Key";
but the code below not
// 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";
the error: "Object reference not set to an instance of an object."
This code does not work, too:
BindingSource bs = new BindingSource(query, null);
aclass.DataSource = bs;