I have just started using WPF forms instead of Windows Forms forms. In a Windows Forms form I could just do:
ComboBox.SelectedValue.toString();
And this would work fine.
How do I do this in WPF? It doesn't seem to have the option.
A ComboBox control is an items control that works as a ListBox control but only one item from the collection is visible at a time and clicking on the ComboBox makes the collection visible and allows users to pick an item from the collection. Unlike a ListBox control, a ComboBox does not have multiple item selection.
I have figured it out a bit of a strange way of doing it compared to the old WF forms:
ComboBoxItem typeItem = (ComboBoxItem)cboType.SelectedItem; string value = typeItem.Content.ToString();
Well.. I found a simpler solution.
String s = comboBox1.Text;
This way I get the selected value as string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With