Can anyone tell me how to get the selected item of a ComboBox
to a string
variable?
string selected = cmbbox.SelectedItem.ToString();
MessageBox.Show(selected);
This gives me System.Data.DataRowView
in my MessageBox
Try this:
string selected = this.ComboBox.GetItemText(this.ComboBox.SelectedItem);
MessageBox.Show(selected);
You can use as below:
string selected = comboBox.selectedItem.ToString();
or
string selected = comboBox.SelectedText;
var selected = cmbbox.GetItemText(cmbbox.Text);
MessageBox.Show(selected);
This also works: CombBoxItem comboBoxItem = comboBox.SelectedItem as ComboBoxItem string text = comboBoxItem.content.ToString();