This is a migrated thread and some comments may be shown as answers.
Error adding new record
5 Answers 135 Views
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 26 Apr 2009, 09:30 PM
I am getting the following error when adding a new record into the observablecollection that is the ItemSource of the grid.

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

Sort by
0
Chris
Top achievements
Rank 1
answered on 26 Apr 2009, 11:29 PM
NOTE: In terms of this issue, as long as I don't have the ItemsSource of the GridView set to _Licenses, then I have no problems adding another License record to the collection. 

I only get the error message when the grid is bound to my collection.

Chris
0
Stefan Dobrev
Telerik team
answered on 27 Apr 2009, 10:35 AM
Hello 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.
0
Chris
Top achievements
Rank 1
answered on 27 Apr 2009, 12:43 PM
Hi Stefan,

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>

 

 

 

 

 

0
Pavel Pavlov
Telerik team
answered on 30 Apr 2009, 08:44 AM
Hello Chris,

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.
0
Brian Matuska
Top achievements
Rank 1
answered on 19 Jun 2009, 05:28 AM
I am getting the same error message.

Here's what my code does.
1) When user selects a file, the file gets read by the BLL and return as a List of some objects.
2) A ObservableCollection object will be new'ed and assigned to grid's ItemsSource.  Items from [step 1] gets added to the collection.
3) a FileSystemWatch even will be create to monitor changes from the file.
4) when  file change event is triggered, i will, just like [step 1],  get a list of some objects back and exclude th existing records.  Then, here's where i'm getting the exception, I call Add() from ObservableCollection object to add the new records.

So, unlike OP which adding new records from grid edit mode, i'm adding new records from external events.

Edit: solved by removing DataLoadMode="Asynchronous"
Asked by
Chris
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Stefan Dobrev
Telerik team
Pavel Pavlov
Telerik team
Brian Matuska
Top achievements
Rank 1
Share this question
or