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

Cell editor shows old value if cell is updated while in edit mode

3 Answers 196 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tom
Top achievements
Rank 1
Tom asked on 03 Aug 2009, 08:10 AM

I've got an editable grid, along with a way that users can set the grid through other fields on the page. When the user does an update through the extra fields, I update the value for the current cell, and the grid displays it all correctly. I've done this either by updating CurrentCell.value, or updating the row data under the cell, and it all works properly.
However if the user first enters edit mode in the cell, then does the external update, then the cell editor for that cell seems to get stuck on the old value. Anything I check, even Cell.Value, Cell.Editor.Value, or my row data.value all appear to have the new data, even if I check it in the BegginingEdit event, however when the editor displays, it switches back to the old value.

Best shown in a sample. To test this, start the app, go into edit mode on a cell, then click the button. If you then go out of the cell you see that the value was updated correctly, but it you click back into edit mode in the cell, the old value redisplays.

I have found the workaround myself and you can see it in the code, but I'm pretty sure the underlying behavour is a bug?

<UserControl  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
    mc:Ignorable="d" xmlns:telerikGridView="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" x:Class="SilverlightApplication1.MainPage" 
    d:DesignWidth="640" d:DesignHeight="480">  
  <Grid x:Name="LayoutRoot">  
 
    <telerikGridView:RadGridView Name="dg1" Margin="0,0,0,167" d:LayoutOverrides="Width, Height" Height="110" VerticalAlignment="Top"/>  
    <Button Name="Button1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Content="Set to 3" Margin="0,120,0,0"/>  
    <TextBlock Name="txt1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="100,120,0,0" /> 
    </Grid> 
</UserControl> 
 

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Net;  
using System.Windows;  
using System.Windows.Controls;  
using System.Windows.Documents;  
using System.Windows.Input;  
using System.Windows.Media;  
using System.Windows.Media.Animation;  
using System.Windows.Shapes;  
using System.Collections.ObjectModel;  
 
namespace SilverlightApplication1  
{  
    public partial class MainPage : UserControl  
    {  
        public ObservableCollection<DataRow> myData;  
 
        public MainPage()  
        {  
            InitializeComponent();  
 
            myData = new ObservableCollection<DataRow>();  
            myData.Add(new DataRow(1));  
            myData.Add(new DataRow(2));  
 
            dg1.ItemsSource = myData;  
 
            this.Button1.Click += new RoutedEventHandler(Button1_Click);  
            this.dg1.BeginningEdit += new EventHandler<Telerik.Windows.Controls.GridViewBeginningEditRoutedEventArgs>(dg1_BeginningEdit);  
 
        }  
 
        void dg1_BeginningEdit(object sender, Telerik.Windows.Controls.GridViewBeginningEditRoutedEventArgs e)  
        {  
            txt1.Text = "e.value is " + e.Cell.Value + ", row val is " + ((DataRow)e.Cell.DataContext).val.ToString();  
        }  
 
        void Button1_Click(object sender, RoutedEventArgs e)  
        {  
            // Putting this line in makes it look like it worked, but click back in and the problem is still there.  
            // dg1.CommitEdit();   
 
            // This sets the value, but the editor will be stuck with the old value  
            dg1.CurrentCell.Value = 3;  
 
            // This works  
            //if (dg1.CurrentCell.IsInEditMode)  
            //{  
            //    dg1.CurrentCell.Editor.Value = 3;  
            //    dg1.CurrentCell.CommitEdit();  
            //}  
            //else  
            //{  
 
            //    dg1.CurrentCell.Value = 3;  
            //}  
 
        }  
    }  
 
    public class DataRow  
    {  
        public DataRow(int newVal)  
        {  
            val = newVal;  
        }  
        public int val  
        {  
            set;  
            get;  
        }  
    }  
}  
 

3 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 06 Aug 2009, 12:00 PM
Hi Tom,

This issue is already fixed, please try it with our latest version.

Best wishes,
Nedyalko Nikolov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Tom
Top achievements
Rank 1
answered on 07 Aug 2009, 03:27 AM
Hi Nedyalko,

I am using the latest internal build, 2009.2.724.1020.

Is there a later one?

Tom
0
Nedyalko Nikolov
Telerik team
answered on 10 Aug 2009, 11:15 AM
Hello Tom,

In a few days a service pack for all WPF/Silverlight controls will be available. New version will do case with CommitEdit() automatically for you (depends from RadGridView.ActionOnLostFocus property), and problem will not present any more (I've just tested all cases).

Indeed with 2009.2.724.1020 there is an issue with common case (my mistake).
Sorry for the inconvenience caused.


Greetings,
Nedyalko Nikolov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Tom
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Tom
Top achievements
Rank 1
Share this question
or