Applying CellEditTemplate to GridViewComboBoxColumn

2 posts, 0 answers
  1. Minh
    Minh avatar
    43 posts
    Member since:
    May 2014

    Posted 03 Dec 2015 Link to this post

    I currently have a column that binds to a collection of enums. I'm trying to change it so that it will display the display attribute name instead of the enum name. I was able to the the CellTemplate to display the correct attribute name but I wasn't able to get the CellEditTemplate to display the the dropdown correct. It doesn't show anything when clicked. 

    My original code that works but doesn't use display name

        <telerik:GridViewComboBoxColumn Header="Event Type" ItemsSource="{Binding ScriptEvents}" DataMemberBinding="{Binding SelectedEvent}"  IsReadOnly="False" />

    What I tried


        <telerik:GridViewComboBoxColumn ItemsSource="{Binding ScriptEvents}" DataMemberBinding="{Binding SelectedEvent}" IsReadOnly="False">
            <telerik:GridViewComboBoxColumn.CellTemplate >
                <DataTemplate>
                    <TextBlock Text="{Binding SelectedEvent, Converter={StaticResource EnumToDisplayAttribConverter}}"/>
                </DataTemplate>
            </telerik:GridViewComboBoxColumn.CellTemplate>
            <telerik:GridViewComboBoxColumn.CellEditTemplate >
                <DataTemplate>
                    <telerik:RadComboBox ItemsSource="{Binding ScriptEvents, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}">
                        <telerik:RadComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding SelectedEvent, Converter={StaticResource EnumToDisplayAttribConverter}}" DataContext="{Binding}"/>
                            </DataTemplate>
                         </telerik:RadComboBox.ItemTemplate>
                     </telerik:RadComboBox>
                 </DataTemplate>
            </telerik:GridViewComboBoxColumn.CellEditTemplate>
        </telerik:GridViewComboBoxColumn>

    Code for enum converter can be found here http://formatexception.com/2014/07/bind-a-combobox-to-an-enum-while-using-display-attribute/ 
  2. Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 08 Dec 2015 Link to this post

    Hi Minh,

    From the provided code I can only be guessing what the cause for the issue might be. Do you experience any BindingErrors when running the application in debug mode? They can be observed in the "output" window in VisualStudio. Can you also share some details on the explicit setting of the DataContext of the TextBlock within the ItemTemplate of RadComboBox?

    Additionally, you can take a look at the ComboBox Column topic for more information on the matter.

    Regards,
    Stefan X1
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top