Olivia Olga Clarissa Olivia Olga Clarissa - 1 year ago 69
C# Question

Getting content value from combo box on C#

can we retrieve the content from combobox without data binding? This is my xaml code

<ComboBox x:Name="Choice" Header="Choice your eating time" PlaceholderText="Pilih" Width="200" SelectionChanged="Choice_SelectionChanged">
<ComboBoxItem Content="Breakfast" />
<ComboBoxItem Content="Lunch" />
<ComboBoxItem Content="Dinner"/>

I tried with
but the result will be Windows.UI.XAML.ComboBox, not the content of combobox. I want to pass it into listbox and when I used
it contain same result with SelectedItem.

Answer Source

@Olivia Olga Clarissa try this ..

Text = ((ComboBoxItem)Choice.SelectedItem).Content.ToString();


var comboBoxItem = Choice.Items[Choice.SelectedIndex] as ComboBoxItem;
if (comboBoxItem != null)
    string selectedcmb = comboBoxItem.Content.ToString();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download