Does a DataGridComboBoxColumn cell not display the selected text of an element?

I was wondering, how do you get a DataGridComboBoxColumn to display the selected text of an element when it is not in edit mode? And is it also possible to make the combo box in edit mode display the selected text of the element?

Here is my XAML:

<DataGridComboBoxColumn Header="Formatter" SelectedItemBinding="{Binding Path=Format}"> <DataGridComboBoxColumn.ElementStyle> <Style TargetType=""> <Setter Property="Text" Value="{Binding Path=FormatView.Name}" /> </Style> </DataGridComboBoxColumn.ElementStyle> <DataGridComboBoxColumn.EditingElementStyle> <Style TargetType="ComboBox"> <Setter Property="ItemsSource" Value="{Binding Path=DefinedFormatters}" /> <Setter Property="IsDropDownOpen" Value="True" /> <Setter Property="ItemTemplate"> <Setter.Value> <DataTemplate> <TextBlock Text="{Binding Path=Name}"></TextBlock> </DataTemplate> </Setter.Value> </Setter> </Style> </DataGridComboBoxColumn.EditingElementStyle> </DataGridComboBoxColumn> 
+4
source share
3 answers

This was the only resource in the DataGridComboBoxColumn that I found useful:

http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridcomboboxcolumn.aspx

Everything else (that I found on sites other than MSDN) was misleading !

+6
source

Ok, I figured it out after a lot of searching.

but it seems that you are just doing the same for ElementStyle, again with the target type of the combo box, even if it does not show ComboBox when it is not being edited.

 <DataGridComboBoxColumn Header="Formatter" SelectedItemBinding="{Binding Path=Format}"> <DataGridComboBoxColumn.ElementStyle> <Style TargetType="ComboBox"> <Setter Property="ItemsSource" Value="{Binding Path=DefinedFormatters}" /> <Setter Property="IsDropDownOpen" Value="True" /> <Setter Property="ItemTemplate"> <Setter.Value> <DataTemplate> <TextBlock Text="{Binding Path=Name}"></TextBlock> </DataTemplate> </Setter.Value> </Setter> </Style> </DataGridComboBoxColumn.ElementStyle> <DataGridComboBoxColumn.EditingElementStyle> <Style TargetType="ComboBox"> <Setter Property="ItemsSource" Value="{Binding Path=DefinedFormatters}" /> <Setter Property="IsDropDownOpen" Value="True" /> <Setter Property="ItemTemplate"> <Setter.Value> <DataTemplate> <TextBlock Text="{Binding Path=Name}"></TextBlock> </DataTemplate> </Setter.Value> </Setter> </Style> </DataGridComboBoxColumn.EditingElementStyle> </DataGridComboBoxColumn> 
+3
source

I don’t understand at all, but maybe I’ll try the following: Remove the ElementStyle and set DisplayMemberPath instead, for example:

 <DataGridComboBoxColumn Header="Formatter" SelectedItemBinding="{Binding Path=Format}" DisplayMemberPath="Name"> 

The path could also be FormatView.Name, I don't have a clear idea of ​​your data structure. And how did you set the ItemSource of your DataGridComboBoxColumn?

0
source

All Articles