我想在組合框wpf中獲取選定的項目。但它返回System.Data.DataRowView。我的代碼在XAML:組合框選定的項目WPF c#
<ComboBox Name="ddDeputi" Margin="131,85,0,0" Width="327" HorizontalAlignment="Left" VerticalAlignment="Top" Height="22"
SelectedValue="{Binding Path = kodeDep, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Validation.ErrorTemplate="{x:Null}" SelectionChanged="ddDeputi_SelectionChanged" Loaded="ddDeputi_Loaded" />
而且在我的.cs:
private void ddDeputi_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (ddDeputi.SelectedIndex != -1)
{
string akode = ddDeputi.SelectedValue.ToString();
DaUnitKerja oDa = new DaUnitKerja();
DataSet data = new DataSet();
data = oDa.TampilDir(akode);
ddDir.ItemsSource = data.Tables[0].DefaultView;
ddDir.DisplayMemberPath = data.Tables[0].Columns["unit_kerja"].ToString();
ddDir.SelectedValuePath = data.Tables[0].Columns["kode"].ToString();
ddSubDir.SelectedIndex = -1;
ComboBoxItem cbi = (ComboBoxItem)ddDeputi.ItemContainerGenerator.ContainerFromItem(ddDeputi.SelectedItem);
txtDeputi.Text = cbi.Content.ToString();
}
}