I’m binding a comboBox to a collection of users sended by a web-service.
When I try to read the selected value using :
string x = comboSpec.SelectedItem.ToString();
or
string x = comboSpec.SelectedValue.ToString();
I get (Breakpoint mode) :
Name | Value | Type
x | "UI.WebServiceReference.Users" | string
How can I get the selected value from the comboBox (like “admin”) and not the type of the binded element ?
If you’re displaying the DisplayMemberPath and have the name set as your value with the SelectedValuePath in the ComboBox definition, then you can use SelectedValue rather than SelectedItem. SelectedItem returns the item in the ItemsCollection whereas SelectedValue returns the property of the item bound.
Here’s an example: