Please provide a LazyDataRecordList or a RecordCollection of DataRecord<License> objects
Parameter name: recordList
It happens on the second line (_Licenses.Add call) which is the collection
private
ObservableCollection<License> _Licenses;
License
license = new License(_subscriberId, _licenseId, _customerId);
_Licenses.Add(license);
Any ideas?
Thanks in advance
Chris
5 Answers, 1 is accepted
I only get the error message when the grid is bound to my collection.
Chris
I have tried to replicate your scenario, but everything seems fine on my side. Can you be more specific when exactly you are trying to insert the new item. If you can provide us more complete sample code it will be great.
I'm also attaching a simple solution that has a button and a grid. Clicking the button adds an object in the underlying observable collection.
Kind regards,
Stefan Dobrev
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.
Thanks for your prompt reply.
What initially prompted me to use a button was the fact that the Insert key wasn't working for me. If you use the following code, run the app, press Insert and modify the record, then hit enter, the record dissapears.
Am I doing something wrong?
Thank you in advance.
Regards,
Chris
Message.cs code
-------------------------
using
System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;
namespace GridViewColumnSortState
{
public class Message: INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public Message(string sender, string subject, int size)
{
Sender = sender;
Subject = subject;
Size = size;
}
public Message(string sender)
{
Sender = sender;
Subject =
string.Empty;
Size = 0;
}
private string _subject;
p
rivate string _sender;
private int _size;
public string Subject
{
get { return _subject; }
set { _subject = value; OnPropertyChanged("Subject"); }
}
public string Sender
{
get { return _sender; }
set { _sender = value; OnPropertyChanged("Sender"); }
}
public int Size
{
get { return _size; }
set { _size = value; OnPropertyChanged("Size"); }
}
protected virtual void OnPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
t
his.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
Page.xaml.cs code
-------------------------
using
System.Collections.Generic;
using
System.Collections.ObjectModel;
using System.Windows.Controls;
using GridViewColumnSortState;
namespace
ErrorAddingNewRecord
{
public partial class Page : UserControl
{
private readonly ObservableCollection<Message> messages;// = GetMessages();
public Page()
{
this.InitializeComponent();
messages =
new ObservableCollection<Message>();
messages.Add(
new Message("tom@hanna-barbera.com", "Cats are cool", 100));
messages.Add(
new Message("jerry@hanna-barbera.com", "Mice are cool", 100 ));
messages.Add(
new Message("spike@hanna-barbera.com", "Dogs are cool", 100 ));
this.GridView.ItemsSource = messages;
}
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
//messages.Add(new Message() { Sender = "tom@hanna-barbera.com", Subject = "", Size = 100 });
//messages.Add(new Message("test@hanna-barbera.com"));
}
private void RadGridView_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
{
Message newMessage = new Message("test@hanna-barbera.com");
e.NewObject = newMessage;
}
}
}
Updated the XAML file as follows
<
telerikGrid:RadGridView Name="GridView" Grid.Row="2" AddingNewDataItem="RadGridView_AddingNewDataItem">
</telerikGrid:RadGridView>
I have tested the scenario. Your code is OK. Unfourtunately I found we have a bug. It prevents the RadGridView to auto save the record when e.NewData is asigned in the AddingNewDataItem handler.
Bellow is a sample workarround ( I have slightly modified your code and added an event handler).
Please see the underlined lines as well as the GridView_RowEditEnded method.
public Page() |
{ |
this.InitializeComponent(); |
messages = new ObservableCollection<Message>(); |
messages.Add(new Message("tom@hanna-barbera.com", "Cats are cool", 100)); |
messages.Add( |
new Message("jerry@hanna-barbera.com", "Mice are cool", 100)); |
messages.Add( |
new Message("spike@hanna-barbera.com", "Dogs are cool", 100)); |
this.GridView.ItemsSource = messages; |
this.GridView.ValidationMode = Telerik.Windows.Data.ValidationMode.Row; |
this.GridView.RowEditEnded += new System.EventHandler<Telerik.Windows.Controls.GridViewRowEditEndedEventArgs>(GridView_RowEditEnded); |
} |
void GridView_RowEditEnded(object sender, Telerik.Windows.Controls.GridViewRowEditEndedEventArgs e) |
{ |
GridViewRow row = e.Row; |
if (e.Row is GridViewNewRow) |
{ |
((ObservableCollection<Message>) this.GridView.ItemsSource).Add((Message)e.NewData); |
} |
} |
Thanks for reporting the bug . We always appreciate a constructive feedback. I have updated your telerik points.
Regards,
Pavel Pavlov
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.