Nested bindings not always being updated

2 posts, 1 answers
  1. Marcus
    Marcus avatar
    14 posts
    Member since:
    Sep 2010

    Posted 05 Jun 2013 Link to this post

    I have a RadGridView bound to a collection containing rows like the following:
    public class RowViewModel : INotifyPropertyChanged
    {
        public RowViewModel(Deal deal)
        {
            Deal = deal;
        }
     
        public Deal Deal { get; private set; }
     
        public event PropertyChangedEventHandler PropertyChanged;
     
        public void UpdateBookingStatus()
        {
            Deal.IsBooked = true;
            Deal.BookingTime = DateTime.UtcNow;
     
            OnPropertyChanged("Deal");
        }
     
        protected virtual void OnPropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
     
    public class Deal
    {
        public string Id { get; private set; }
        public DateTime ReceivedTime { get; private set; }
        public DateTime? BookingTime { get; set; }
        public bool IsBooked { get; set; }
     
        public Deal(string id, DateTime receivedTime)
        {
            Id = id;
            ReceivedTime = receivedTime;
        }
    }

    My grid has 4 columns bound to each of the Deal properties, with bindings such as 'Deal.Id', 'Deal.ReceivedTime', etc.

    All displays correctly, but when I call the UpdateBookingStatus method, which updates a couple of Deal properties and then fires a PropertyChanged event on the Deal itself, the Deal.BookingTime and Deal.IsBooked column values are not always refreshed in the grid.  If I scroll the relevant rows out of view and then back into view, the values are updated correctly.

    Is this expected?  Am I not supposed to be setting nested bindings on Columns?  Should the grid not listen for the OnPropertyChanged("Deal"event and update all columns using that property?

    Thanks.
    Marcus.
  2. Answer
    Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 07 Jun 2013 Link to this post

    Hello,

    We have tried to reproduce this, but the cells update in our project.

    I have attached a sample project. Can you please take a look. Can you update the sample project so it reproduces the behavior?

    For the filtering, sorting and grouping (the view) to update after data changes you will need to use this approach and call BeginEdit and EndEdit. We don't recreate the entire view on each PropertyChanged for performance reasons. When you call BeginEdit and EndEdit we will take the edited item and calculate what to do with it -- i.e. hide/show it based on filtering criteria, move it somewhere else if there is sorting or grouping. But we will not recreate the entire view from scratch which might be a very costly operation.

    Alternatively, if you don't care about performance that much, you can call RadGridView.Rebind() or throw a CollectionChanged Reset from your items source and the entire view will be recreated from scratch.

    I hope this helps.

    Regards,
    Rossen Hristov
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top