Reputation: 2153
I have a grid such that when I load the grid it's populated with "Active Records". Every column populates properly except the enum column, the enum colkumn is blank. The combobox I can click into and it is populated with the enums.
If I can get some help to setting the enum to display correctly please.
<telerik:GridViewComboBoxColumn Width="100"
DataMemberBinding="{Binding Occurence}"
ItemsSource="{Binding Source={x:Type accounts:Insurance+Occurences}, Converter={StaticResource EnumToArrayConverter}}">
</telerik:GridViewComboBoxColumn>
<telerik:GridViewDataColumn Header="Rate" DataMemberBinding="{Binding Rate, StringFormat='#,##0.#0'}">
<telerik:GridViewDataColumn.CellEditTemplate>
<DataTemplate>
<TextBox Text="{Binding Rate, Mode=TwoWay, StringFormat='#,##0.#0', UpdateSourceTrigger=PropertyChanged}" HorizontalContentAlignment="Right" />
</DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>
<ObjectDataProvider x:Key="MyEnumDataProvider" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="accounts:InsuranceTypes"></x:Type>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
EnumToArrayConverter is from WPF: How to populate combobox with enum in Xaml
The Rates column populates but the enum column remains empty.
Upvotes: 1
Views: 608
Reputation: 4116
Following code will solve it using object data provider
<ObjectDataProvider MethodName="GetValues"
ObjectType="{x:Type sys:Enum}"
x:Key="EnumDataProvider">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="local:SomeENUM" />
</ObjectDataProvider.MethodParameters>
then use data column and override its template to have combobox in it and bind combo box like this
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Source={StaticResource EnumDataProvider}}"
SelectedItem="{Binding selectedEnum}"/>
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
Upvotes: 1