I have a simple comboBox with some Value/Text items in it. I have using ComboBox.DisplayMember and ComboBox.ValueMember to correctly set the value/text. When I try to get th
Not sure why SelectedValue
doesn't return anything... I assume it could be due to the fact that you're not using data binding (DataSource
). You should try to assign a list of cards to the DataSource
property.
Regarding the issue with SelectedItem
: ComboBox.SelectedItem
is of type Object
, which doesn't have a property named Value
. You need to cast it to the item's type ; but since it is an anonymous type, you can't... you should probably create a type to hold the value and text of the card, and cast to this type :
Card card = ComboBox.SelectedItem as Card;
if (card != null)
{
// do something with card.Value
}