I\'v got a combobox that I created as a user control(it\'s actually made up of a label, combobox and textbox). I\'m trying to bind a dataset to the combobox datasource, but
I had the same issue and found a solution that may not apply to your problem, but might be helpful for others:
A property marked with the [Browsable(false)]
-Attribute will also cause this exception when trying to bind to it.
Moved away from using a Datatset. Created a class("Facilities") that will hold an ID and Name values. Changed "info" to a List type. Then the following code worked just fine:
info.Add(new Facilities { ID = dr["other_facility_id"].ToString(), Name = dr["other_facility_name"].ToString() });
((ucComboBox)ctrl).combobox.DataSource = new BindingSource(info, null);//info;
((ucComboBox)ctrl).combobox.ValueMember = "ID";
((ucComboBox)ctrl).combobox.DisplayMember = "Name";
No issues with binding that.
I had same issue while binding. I reversed the order and everything started working. The original code will look like this
((ucComboBox)ctrl).combobox.ValueMember = "radiology_id";
((ucComboBox)ctrl).combobox.DisplayMember = "radiology_name";
((ucComboBox)ctrl).combobox.DataSource = info;
Surely the fragment of code below is going to cause an issue?
public string value
{
get { return _value ; }
set { _value = value; }
}
You need to name this something else e.g. comboValue. "value" represents the implicit variable passed into a property declaration.
i.e.
public string comboValue
{
get { return _value ; }
set { _value = value; }
}
I think you have the property Modifiers of your combo to something different from Public.
However I will choose to implement two new public properties at the usercontrol level.
DisplayMember
and ValueMember
just to avoid that ugly cast.
In the set/get accessor I will reflect the values in/from the internal combo
public string DisplayMember
{
get { return combobox1.DisplayMember; }
set { combobox1.DisplayMember = value;}
}
public string ValueMember
{
get { return combobox1.ValueMember; }
set { combobox1.ValueMember = value;}
}
Also make sure the ID and Name properties are Public otherwise you get the error:
Cannot bind to the new display member.