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; |
} |
} |
} |