Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get combobox set value as string

Tags:

c#

combobox

Found several ways to do so, but none of them works for me.. I have a combobox with variable number of options (taken from dynamic xml file). For next, I need to know what the user choosed, and I cant find out how to do it. This is one of ways I found and tried:

string myString = myCombobox.SelectedValue.ToString();

At least I dont get an error, but when I try to show that string, it does nothing.

like image 466
Marek Buchtela Avatar asked Dec 06 '22 10:12

Marek Buchtela


1 Answers

Had a similar problem, try this:

string myString = ((ComboBoxItem)myCombobox.SelectedItem).Content.ToString();

It works for me!

Just try to understand seeing myCombobox design.

like image 99
mangatinanda Avatar answered Dec 15 '22 00:12

mangatinanda