This question is locked. New answers and comments are not allowed.
I have the following column set up:
The CellEditTemplate is never activated. However, if I remove the CellTemplate it is.
How can I get a CellEditTemplate to be used alongside a CellTemplate, and to activate edit mode according to the columns EditTriggers property?
<telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}"> <telerik:GridViewDataColumn.CellTemplate> <DataTemplate> <TextBox Background="Yellow" Text="{Binding Name}"/> </DataTemplate> </telerik:GridViewDataColumn.CellTemplate> <telerik:GridViewDataColumn.CellEditTemplate> <DataTemplate> <TextBox Background="Red" Loaded="TextBox_Loaded" Text="{Binding Name}"/> </DataTemplate> </telerik:GridViewDataColumn.CellEditTemplate> </telerik:GridViewDataColumn> </telerik:RadGridView.Columns>The CellEditTemplate is never activated. However, if I remove the CellTemplate it is.
How can I get a CellEditTemplate to be used alongside a CellTemplate, and to activate edit mode according to the columns EditTriggers property?
5 Answers, 1 is accepted
0
Hello Mark,
Greetings,
Vanya Pavlova
the Telerik team
Looking at your xaml markup both CellTemplate and CellEditTemplate are for editing. In this case a cell in this column never enters edit mode. Just replace the TextBox control in the defined CellTemplate with a single TextBlock and it will work as expected:
Copy Code
Copy Code
<telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}"> <telerik:GridViewDataColumn.CellTemplate> <DataTemplate> <Border Background="Yellow"> <TextBlock Text="{Binding Name}"/> </Border> </DataTemplate> </telerik:GridViewDataColumn.CellTemplate> <telerik:GridViewDataColumn.CellEditTemplate> <DataTemplate> <TextBox Background="Red" Loaded="TextBox_Loaded" Text="{Binding Name}"/> </DataTemplate> </telerik:GridViewDataColumn.CellEditTemplate> </telerik:GridViewDataColumn> </telerik:RadGridView.Columns>Greetings,
Vanya Pavlova
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Mark
Top achievements
Rank 1
answered on 04 Mar 2011, 04:23 PM
That does work and the edit template is activated. However on hitting enter in the TextBox, the focus does not move to the next row like it does with the default templates. How can we achieve this behaviour when using edit templates?
0
Hi Mark,
Vanya Pavlova
the Telerik team
I have just tested this behavior and everything works fine on my side. May you share with us the source code you are currently using so that we can see what happens in your project? Any additional information about the grid version you are using will be highly appreciated as well.
Vanya Pavlova
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Mark
Top achievements
Rank 1
answered on 07 Mar 2011, 09:45 AM
OK thanks here is the XAML:
and the code behind:
<UserControl x:Class="SilverlightApplication5.MainPage" xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"> <UserControl.Resources> <ResourceDictionary> </ResourceDictionary> </UserControl.Resources> <Grid x:Name="LayoutRoot"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="20"/> </Grid.RowDefinitions> <telerik:RadGridView x:Name="RadGridView1" AutoGenerateColumns="False" BorderBrush="#FFE51A1A" BorderThickness="2"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn Header="ID" DataMemberBinding="{Binding ID}"> </telerik:GridViewDataColumn> <telerik:GridViewDataColumn UniqueName="Mjs" Header="Name"> <telerik:GridViewDataColumn.CellTemplate> <DataTemplate> <Border BorderBrush="Green" BorderThickness="2"> <Border BorderBrush="Yellow" BorderThickness="2" > <TextBlock Name="NameTextBox" Text="{Binding Path=Name}" /> </Border> </Border> </DataTemplate> </telerik:GridViewDataColumn.CellTemplate> <telerik:GridViewDataColumn.CellEditTemplate> <DataTemplate> <Border BorderBrush="Red" BorderThickness="2"> <Border BorderBrush="Orange" BorderThickness="2" > <TextBox Text="{Binding Name, Mode=TwoWay}" /> </Border> </Border> </DataTemplate> </telerik:GridViewDataColumn.CellEditTemplate> </telerik:GridViewDataColumn> </telerik:RadGridView.Columns> </telerik:RadGridView> </Grid></UserControl>and the code behind:
using System;using System.ComponentModel;using System.Linq;using System.Windows.Controls;namespace SilverlightApplication5{ public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); var itemsSource = from i in Enumerable.Range(1, 10) select new MyObject() { ID = i, Name = (i < 5) ? "Name1" : "Name2" }; RadGridView1.ItemsSource = itemsSource; } } public class MyObject : INotifyPropertyChanged { private int id; public int ID { get { return id; } set { id = value; } } private string name; public string Name { get { return name; } set { name = value; OnPropertyChanged("Name"); } } private void OnPropertyChanged(string name) { if (PropertyChanged!=null) PropertyChanged(this, new PropertyChangedEventArgs(name)); } public event PropertyChangedEventHandler PropertyChanged; }}0
Hello Mark,
Thank you for sending this snippet to us. The main problem is that you have missed to call the ToList() extension method, as shown below:
Best wishes,
Vanya Pavlova
the Telerik team
Thank you for sending this snippet to us. The main problem is that you have missed to call the ToList() extension method, as shown below:
Copy Code
var itemsSource = (from i in Enumerable.Range(1, 10) select new MyObject() { ID = i, Name = (i < 5) ? "Name1" : "Name2" }).ToList(); RadGridView1.ItemsSource = itemsSource;Best wishes,
Vanya Pavlova
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!