I have a ComboBox and its ComboBoxItem are all generated in run time (programmatically). Whenever there a ComboBox.SelectionChange, the program will show a MessageBox showing the selected content of the ComboBox
private void cb2_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MessageBox.Show(cb2.SelectedItem.ToString());
}
However, it is show me:
System.Windows.Controls.ComboBoxItem: Hello World
I only want to show “Hello World” but not the “System….” thing. I tried SelectedValue and that’s showing the same thing as well.
You need to cast the selected item to a ComboBoxItem and only get its content.