All my binding code is in code-behind. I am using:
this.cboPB.ItemsSource = MyClass.Instance.MyDictionary();
this.cboPB.DisplayMemberPath = "Value";
this.cboPB.SelectedItem = "Key"; // THIS IS NOT AVAILABLE - HOW DO IDO THIS?
The dictionary referenced above is defined as type MyDictionary<int, string>();
Please help. Thanks.
Hi Jay,
I am just checking if my last reply was helpful for you.
If you require any further assistance, please do not hesitate to ask.
Hello Jay,
The SelectedItem of the combo editor could be accessed using the SelecteItem property. The following code snippet shows how to get Key and Value of the returned KeyValuePair :
var myValue = ((KeyValuePair<int, string>)cboPB.SelectedItem).Value;
var myKey = ((KeyValuePair<int, string>)cboPB.SelectedItem).Key;
Actually, let's say the user selects a value in the combo-box, and click a button on the form, how do I get the selected key/value?
myValue = this.cbo.Value; // this does not work as Value is an element of the Dictionary.
In your example, if the user selects "three", how do I get: myValue = 3 // this would be in the code behind a button on the form.
Thanks.
Thank you for your feedback Jay. This could help to other community members as well.
Got it - thanks.