I have a ComboBox that is binded to a DataSet. I wanted to show the selected value whenever the ComboBox has a change in selection. I have the following code:
private void devCb1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
dv = new DataView(
dt,
"Device_ID = " + devCb1.SelectedIndex,
"Data_ID ASC",
DataViewRowState.CurrentRows);
dataDg1.ItemsSource = dv;
devCb1.DisplayMemberPath = "Content";
MessageBox.Show(devCb1.SelectedValue.ToString());
}
But it only gives me
System.Data.DataRowView
I have already set the DisplayMemberPath, but it still not showing me the selected item’s content. What is wrong?
[EDITED]
I also tries the following
devCb1.SelectedValuePath = "Content";
MessageBox.Show(devCb1.SelectedValue.ToString());
But it also still gives me
System.Data.DataRowView
Doesn’t work either..
DataRowViewhas no content from what i can see. YourSelectedValuePathshould point toRowi think (or if the current path correctly points to theContentof theComboBoxItemyou just need to cast at that point), and you’d still need to cast theSelectedValuebeing a row, to that class and from there you can get some of its content.Set breakpoints, use the debugger, look at the data in your objects.