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

ActionOnLostFocus="CommitEdit" Does Not Work When Cell EditTemplate is Used

1 Answer 171 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bob The Kiwi
Top achievements
Rank 1
Bob The Kiwi asked on 05 Dec 2009, 01:23 AM
Hi Telerik

In the following xaml I have set up a RadGridView with two columns:

       <t:RadGridView ItemsSource="{Binding Persons}"  ActionOnLostFocus="CommitEdit" AutoGenerateColumns="False" > 
            <t:RadGridView.Columns> 
                <!-- Auto column --> 
                <t:GridViewDataColumn DataMemberBinding="{Binding Path=ID}"  /> 
                <!-- Manual column --> 
                <t:GridViewDataColumn DataMemberBinding="{Binding Name}"
                    <t:GridViewDataColumn.CellTemplate> 
                        <DataTemplate> 
                            <TextBlock Text="{Binding Name}" /> 
                        </DataTemplate> 
                    </t:GridViewDataColumn.CellTemplate> 
                    <t:GridViewDataColumn.CellEditTemplate> 
                        <DataTemplate> 
                            <TextBox Text="{Binding Name,Mode=TwoWay}" /> 
                        </DataTemplate> 
                    </t:GridViewDataColumn.CellEditTemplate> 
                </t:GridViewDataColumn> 
            </t:RadGridView.Columns> 
        </t:RadGridView>       

This xaml was placed in a window with the following code behind:

using System.Collections.ObjectModel; 
using System.Windows; 
 
namespace WpfApplication2 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
        public MainWindow()        { 
            InitializeComponent(); 
            this.DataContext = this
        } 
 
        public ObservableCollection<Employee> Persons 
        { get { return EmployeeService.GetEmployees(); } } 
 
    } 
    public class Employee    { 
        public int ID { getset; } 
        public string Name { getset; } 
    } 
    public class EmployeeService    { 
        public static ObservableCollection<Employee> GetEmployees() 
        { 
            ObservableCollection<Employee> employees = new ObservableCollection<Employee>(); 
            Employee employee = new Employee(); 
            employee.Name = "Maria"
            employee.ID = 24890; 
 
            employees.Add(employee); 
            employee = new Employee(); 
            employee.Name = "Ana"
            employee.ID = 23890; 
 
            employees.Add(employee); 
            employee = new Employee(); 
            employee.Name = "Antonio"
            employee.ID = 24890; 
 
            employees.Add(employee); 
            employee = new Employee(); 
 
            return employees; 
        } 
    } 
 

Now if you run this code you will notice that the two DataGrid columns behave differently when you are updating them. As I understand, when ActionOnLostFocus is set to "CommitEdit" the cell being edited should save its new value when it looses focus. The cells in the first column behave in this fashion, however those in the second column do not - Each reverts to its old value whenever it looses focus.

Why is this? How do I change the behavior of the cells in the second column so that each cell saves its new value when focus is transfered elsewhere?

Cheers

Bob

1 Answer, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 09 Dec 2009, 11:49 PM
Hi Bob The Kiwi,

Indeed there is a problem with scenario using CellEditTemplate. Thank you for pointing this out - I've updated your Telerik points accordingly. The issue is already and will be available with the next latest internal build.


Regards,
Nedyalko Nikolov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Bob The Kiwi
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Share this question
or