This error occures when you're in edit mode for a cell and you press Home or End.
It seems to be related to the selected item not being fully synched with the collection.
The property IsSynchronizedWithCurrentItem set to true and making sure that the selected item is in synch
seems to have fixed the issue for standard edit cells however the error once again occured when in a combobox column
and pressing home or end. Ignoring Home and End on KeyDown event of course also solves the issue.
The collection bound in both cases is a EntitySet<T> cast as a IEnumerable<T> from WCF Ria Services.
Message: Unhandled Error in Silverlight Application
Code: 4004
Category: ManagedRuntimeError
Message: System.NullReferenceException: Object reference not set to an instance of an object.
vid Telerik.Windows.Controls.GridView.GridViewDataControl.GetRowForItem(Object item, Boolean forceGroupExpand)
vid Telerik.Windows.Controls.GridView.GridViewDataControl.TryFindCell(Object item, GridViewColumn column)
vid Telerik.Windows.Controls.GridView.GridViewDataControl.OnHomeOrEndKeyDown(KeyEventArgs e)
vid Telerik.Windows.Controls.GridView.GridViewDataControl.OnKeyDown(KeyEventArgs e)
vid System.Windows.Controls.Control.OnKeyDown(Control ctrl, EventArgs e)
vid MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
Line: 56
Char: 13
Code: 0
Are you able to assist me or do you need more information?
Tomas
5 Answers, 1 is accepted
I could not reproduce the problem in a simple project. Please find it attached and let me know if you manage to reproduce it.
Sincerely yours,
Veselin Vasilev
the Telerik team
Hi Veselin,
I wasn't able to reproduce the error in your sample project, however with a small modification I was able to reproduce it.
Here's what I changed:
MainPage.xaml
<UserControl x:Class="RadControlsSilverlightApp12.MainPage" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 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" xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices" xmlns:my="clr-namespace:RadControlsSilverlightApp12.Web" x:Name="telerikExample"> <Grid x:Name="LayoutRoot"> <!--<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my:Customer, CreateList=true}" Height="0" LoadedData="customerDomainDataSource_LoadedData" Name="customerDomainDataSource" QueryName="GetCustomersQuery" Width="0"> <riaControls:DomainDataSource.DomainContext> <my:DomainService1 /> </riaControls:DomainDataSource.DomainContext> </riaControls:DomainDataSource> <telerik:RadGridView ItemsSource="{Binding ElementName=customerDomainDataSource, Path=Data}" IsSynchronizedWithCurrentItem="False" ShowInsertRow="True" IsBusy="{Binding IsBusy, ElementName=customerDomainDataSource}" Name="gridView" >--> <telerik:RadGridView ItemsSource="{Binding Customers}" IsSynchronizedWithCurrentItem="False" ShowInsertRow="True" Name="gridView"> </telerik:RadGridView> </Grid> </UserControl>MainPage.xaml.cs
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 Telerik.Windows.Controls.GridView; using RadControlsSilverlightApp12.Web; namespace RadControlsSilverlightApp12 { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); this.gridView.DataLoaded += new EventHandler<EventArgs>(gridView_DataLoaded); telerikExample.DataContext = this; MyDataContext.Load(MyDataContext.GetCustomersQuery()); } private DomainService1 myDataContext = new DomainService1(); public DomainService1 MyDataContext { get { return myDataContext; } set { myDataContext = value; } } public IEnumerable<Customer> Customers { get { return MyDataContext.Customers; } } void gridView_DataLoaded(object sender, EventArgs e) { } private void customerDomainDataSource_LoadedData(object sender, System.Windows.Controls.LoadedDataEventArgs e) { if (e.HasError) { System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK); e.MarkErrorAsHandled(); } //if (this.gridView.GroupDescriptors.Count == 0) //{ // ColumnGroupDescriptor cgd = new ColumnGroupDescriptor() // { // Column = this.gridView.Columns["CompanyName"] // }; // this.gridView.GroupDescriptors.Add(cgd); //} } } } Two important things to note here is that ShowInsertRow must be set to True
and you have to use a codebehind approach when binding instead of using the dds.
Setting IsSynchronizedWithCurrentItem to True seems to fix it sometimes, however we've expericend this crash
with various combinations depending on the collection we've used when binding.
The attached code is however the simplest way to make it crash.
Please let me know if you need more information.
Tomas
Thank you for the clarifications. Can you please try the following - do not set the ItemsSource property of the RadGridView in XAML, but set it once the data is loaded:
public MainPage(){ InitializeComponent(); LayoutRoot.DataContext = this; Action<LoadOperation<Customer>> callback = new Action<System.ServiceModel.DomainServices.Client.LoadOperation<Customer>>( (e) => { var entities = e.AllEntities; this.gridView.ItemsSource = entities; }); MyDataContext.Load(MyDataContext.GetCustomersQuery(), callback, null); }I hope that this is a feasible solution for you.
Kind regards,
Veselin Vasilev
the Telerik team
Hi Veselin,
I just tried your suggestion, and it's totally not working.
First I'm no longer able to add new rows and secodnly I found a very strange thing.
With the ShowInsertRow property still set to true and then clicking on the row saying "Click here to add new item" nothing happens as insert is no longer working but if you after that double click a cell on an existing row to go to edit mode and then click out to exit edit mode you get a copy of that row in the grid, repeat the process and you soon have a lot of duplicate rows.
Please advice how to proceed
Tomas
To fix this problem, please call the ToList() method of the entities:
public MainPage(){ InitializeComponent(); LayoutRoot.DataContext = this; Action<LoadOperation<Customer>> callback = new Action<System.ServiceModel.DomainServices.Client.LoadOperation<Customer>>( (e) => { var entities = e.AllEntities; this.gridView.ItemsSource = entities.ToList(); }); MyDataContext.Load(MyDataContext.GetCustomersQuery(), callback, null);}Kind regards,
Veselin Vasilev
the Telerik team