In my project i have a data grid with three combo box template columns. and the combo box is data bind using xaml. But when I run the project combo box is showing system.data.dataRowView
. here is my code for the data grid cell
<DataGridTemplateColumn Header="Category" Width="*" x:Name="categoryColumn">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="categoryBox"
IsEditable="True"
fa:FocusAttacher.Focus="True"
controls:TextBoxHelper.ClearTextButton="True"
controls:TextBoxHelper.SelectAllOnFocus="True"
controls:TextBoxHelper.Watermark="Category"
MaxDropDownHeight="125"
SelectionChanged="CategoryBox_OnSelectionChanged"
IsSynchronizedWithCurrentItem="True"
DisplayMemberPath="{Binding CategoriesCollection.Columns[1]}"
SelectedValuePath="{Binding CategoriesCollection.Columns[0]}"
ItemsSource="{Binding Path=DataContext.CategoriesCollection.DefaultView,
RelativeSource={RelativeSource FindAncestor, AncestorType=DataGrid}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Why it is not showing the correct data. Can anyone suggest me a way to fix this
The code DisplayMemberPath="{Binding CategoriesCollection.Columns[1]}"
is failing because it has to be given a relative source binding just as the ItemsSource
binding you present.
Either provide a proper binding for Displaymember path
{Binding Path=DataContext.CategoriesCollection.Columns[1],
RelativeSource={RelativeSource FindAncestor, AncestorType=DataGrid}}"`
or hard code it to be the target property name which is sought.