I am working with WPF using Entity Framework and Data Binding for managing PRODUCT and BRAND in a database. PRODUCT includes a BrandID property. In order to display in a datagrid a brand name instead of an ID, I used a DataGridComboBoxColumn like this:
C#
gridProducts.DataContext = this.DbContext.Products;
brandColumn.ItemsSource = this.DbContext.Brands;
XAML
<DataGrid Name="gridProducts" IsSynchronizedWithCurrentItem="True"
RowEditEnding="dg_RowEditEnding" ItemsSource="{Binding}" >
<DataGrid.Columns>
...
<DataGridComboBoxColumn Header="BRAND" x:Name="brandColumn" DisplayMemberPath="BrandName"
SelectedValuePath="ID" SelectedValueBinding="{Binding Path=BrandID}" />
</DataGrid.Columns>
<DataGrid>
It works fine. But now I need to bind the combobox selected value into a textbox text. I tried this:
XAML
<TextBox Name="brand" Text="{Binding Path=SelectedValue.Content,
ElementName=brandColumn}"/>
But it doesn't work. Any idea of how can I bind the combobox selected value (the BrandName - not the BrandID) in the textbox?