I found this on Stack Overflow, but no where I could get an answer.
I want to bind a ComboBox of a data grid to a property of a class
which returns [one of the ] Enum Value.
MyEnum
{
[StringValue("SomeVal")]
SomeVal,
[StringValue("AnotherVal")]
AnotherVal,
[StringValue("OneMoreVal")]
OneMoreVal
}
class MyClass
{
public MyEnum A_Value
{
return whatever; // whatever is MyEnum type
}
}
Now I made a Data grid column having combo box and there I need to bind a property
myCombo.DataSource = Enum.GetValues(typeof(MyEnum));
myCombo.DataBindings.Add("SelectedValue", myDataSource, bindingPath + ".A_Value");
When I run this code, it fails with error
"Cannot set a value to a combo box without a ValueMember"
Then I add below line
myCombo.ValueMember = "Value";
It does not fail this time, but no selected value is set. Can someone help me out with the problem ?
What I referred: