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

Observable collection is read-only?

2 Answers 135 Views
GridView
This is a migrated thread and some comments may be shown as answers.
madladuk
Top achievements
Rank 2
madladuk asked on 11 Jan 2011, 05:48 PM
Hi all.

I am trying to create/update/remove aspnet users using the gridview. I have a class that inherits from the INotifyPropertyChanged however when I try to delete a record in the grid it errors and says that the collection is read-only, please could you throw some light on this;

public sealed partial class RegistrationData : INotifyPropertyChanged
    {
        /// <summary>
        /// Gets and sets the user name.
        /// </summary>
        [Key]
       public string UserName { get; set; }
}

public ObservableCollection<RegistrationData> GetWebUsers()
       {
           System.Collections.ObjectModel.ObservableCollection<RegistrationData> Users = new System.Collections.ObjectModel.ObservableCollection<RegistrationData>();
           var users = Membership.GetAllUsers();
           foreach (MembershipUser u in users)
           {
               ProfileBase profile = ProfileBase.Create(u.UserName, u.IsOnline);
               Users.Add(new RegistrationData
               {
                   UserName = u.UserName,
                   Email = u.Email,
                   IsOnline = u.IsOnline,
                   LastActivityDate = u.LastActivityDate,
                   LastLockoutDate = u.LastLockoutDate,
                   LastLoginDate = u.LastLoginDate,
                   Question = u.PasswordQuestion,
                   FriendlyName = profile.GetPropertyValue("FriendlyName").ToString(),
                   PersonGuid = (System.Guid)profile.GetPropertyValue("PersonGuid"),
                   PasswordChange = (bool)profile.GetPropertyValue("PasswordChange"),
               });
           }
           return Users;
           //.OrderBy(e => e.UserName);
       }

void MyData_LoadedData(object sender, LoadedDataEventArgs e)
       {
           try
           {
               this.MyData.LoadedData -= MyData_LoadedData;
               if (e.HasError)
               {
                   e.MarkErrorAsHandled();
                   MessageBox.Show("Unable to load user data please try again.", "Warning", MessageBoxButton.OK);
               }
               else
               {
                   radGridView1.ItemsSource = e.AllEntities;
               }
           }
           catch (Exception ex)
           {
           }
           finally
           {
               radBusy.IsBusy = false;
           }
       }


if (MessageBox.Show(ApplicationStrings.DeleteRecordWarning, "Warning", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                    {
                        this.radGridView1.Items.Remove(this.radGridView1.SelectedItem);
                    }

2 Answers, 1 is accepted

Sort by
0
madladuk
Top achievements
Rank 2
answered on 11 Jan 2011, 06:42 PM
okay think I have sorted it, only problem now is then when I delete data from the DataView the grid does not update? The return type i IEnumerable<MembershipUserService>. If I do MyData.DataView.Remove(radGridView1.SelectedItem) the item is removed however the Grid does not update. I tried to inherit the MembershipUserService from INotifyPropertyChanged but still no refresh on the grid?

P
0
Vlad
Telerik team
answered on 12 Jan 2011, 08:14 AM
Hi,

 Your collection should be INotifyCollectionChanged to achieve your goal - not INotifyPropertyChanged.

Kind regards,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
madladuk
Top achievements
Rank 2
Answers by
madladuk
Top achievements
Rank 2
Vlad
Telerik team
Share this question
or