Observable collection is read-only?

3 posts, 0 answers
  1. madladuk
    madladuk avatar
    126 posts
    Member since:
    Dec 2009

    Posted 11 Jan 2011 Link to this post

    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. madladuk
    madladuk avatar
    126 posts
    Member since:
    Dec 2009

    Posted 11 Jan 2011 Link to this post

    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
  3. DevCraft banner
  4. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 12 Jan 2011 Link to this post

    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>>
Back to Top