This is a migrated thread and some comments may be shown as answers.

Can't use CellEditTemplateSelector & CellTemplateSelector together

2 Answers 149 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shmulik
Top achievements
Rank 1
Shmulik asked on 28 Oct 2010, 10:59 AM

Hi,

I'm using RadGridView to display object's properties, like a PropertyGrid.

I need to change the template of the cell according to the type of the property.

I defined templates for text, color, and enum, also two template selectors, one for edit and one for normal mode.

For example, an enum should be edit  by choosing an item out of a combobox and to be displayed in a TextBlock.

The problem, is when I set the enum template for both the edit selector and normal selector, the combobox is not displayed in edit mode, like this template is ignored.

In resources: 

        <DataTemplate x:Key="TextPropertyValueEditTemplate">
            <TextBox Text="{Binding PropertyValue, Mode=TwoWay}" />
        </DataTemplate>
        
<
DataTemplate x:Key="ColorPropertyValueEditTemplate">
            <telerik:RadColorPicker SelectedColor="{Binding PropertyValue, Mode=TwoWay}" ColorButtonStyle="{StaticResource ColorButtonStyle}" />
        </DataTemplate>
        
<
DataTemplate x:Key="EnumPropertyValueEditTemplate">
            <ComboBox Text="{Binding PropertyValue, Mode=OneWay}"
                          SelectedValue="{Binding PropertyValue, Mode=TwoWay}" 
                          ItemsSource="{Binding EnumNames}"   />
        </DataTemplate>

        <DataTemplate x:Key="EnumPropertyValueNormalTemplate">
                        <TextBox Text="{Binding PropertyValue}" />
                </DataTemplate>


        <Controls:PropertyValueDataTemplateSelector x:Key="PropertyValueEditTemplateSelector"
                                                           TextTemplate="{StaticResource TextPropertyValueEditTemplate}" 
                                                           ColorTemplate="{StaticResource ColorPropertyValueEditTemplate}"
                                                           EnumTemplate="{StaticResource EnumPropertyValueEditTemplate}"
                                                          />
        <Controls:PropertyValueDataTemplateSelector x:Key="PropertyValueTemplateSelector"
                                                           ColorTemplate="{StaticResource ColorPropertyValueEditTemplate}"
                                                           EnumTemplate="{StaticResource TextPropertyValueEditTemplate}"
                                                           />


In the grid:

<telerik:RadGridView Name="dataGrid1"
                             AutoGenerateColumns="False" 
                             ShowGroupPanel="False"
                             ShowColumnHeaders="False"
                             >

            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn  Header="Name" Width="120" 
                                             DataMemberBinding="{Binding PropertyName}"/>
                <telerik:GridViewDataColumn  Header="Value" Width="100*"
                                             DataMemberBinding="{Binding PropertyValue}" 
                                             CellTemplateSelector="{StaticResource PropertyValueTemplateSelector}"
                                             CellEditTemplateSelector="{StaticResource PropertyValueEditTemplateSelector}" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

Now, I know one way to make this sample work, is just to remove the EnumTemplate
from propertyValueTemplateSelector (Normal), It will work, but I have other types I want to
display differently in edit and normal mode.

Appreciate for any help.

2 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 02 Nov 2010, 06:24 PM
Hi Shmulik,

Using the code-snippet you provided, the only visible reason for the undesired behavior may be presumed to be the implementation of the TextBox. You may try to use a TextBlock instead. I am sending you the sample project I have sued for reproducing the issue. In case it does not correspond to your case, I would need more details about your exact scenario.

Kind regards,
Maya
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Shmulik
Top achievements
Rank 1
answered on 03 Nov 2010, 12:30 PM

I see it now, when I use a TextBox for the display template, the control in edit template is not shown. 

Using a TextBlock instead solves it.

Thank you.

Tags
GridView
Asked by
Shmulik
Top achievements
Rank 1
Answers by
Maya
Telerik team
Shmulik
Top achievements
Rank 1
Share this question
or