0

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"/>
 </ComboBox>

I tried with choice.SelectedItem.ToString() 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 choice.SelectedValue.ToString() it contain same result with SelectedItem.

  • try the `SelectedValue` property – NtFreX Nov 24 '16 at 13:02
  • 2
    Possible duplicate of http://stackoverflow.com/questions/4902039/difference-between-selecteditem-selectedvalue-and-selectedvaluepath – Thomas Weller Nov 24 '16 at 13:11
  • @ThomasWeller, I understand the differences between SelectedItems, SelectedIndex, and SelectedValue, I tried to pass it to listbox and it shows Windows.UI.Xaml.ComboBox (I'm forgot the result). – Olivia Olga Clarissa Nov 24 '16 at 14:00

2 Answers2

2

@Olivia Olga Clarissa try this ..

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

or

var comboBoxItem = Choice.Items[Choice.SelectedIndex] as ComboBoxItem;
if (comboBoxItem != null)
{
    string selectedcmb = comboBoxItem.Content.ToString();
}
Mohit Solanki
  • 261
  • 3
  • 17
1

use choice.SelectedItem.Content, in case you are not seeing the property, cast it to ((ContentControl)choice.SelectedItem).Content

Vilsad P P
  • 1,529
  • 14
  • 23