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

Nested bindings not always being updated

1 Answer 42 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marcus
Top achievements
Rank 1
Marcus asked on 05 Jun 2013, 08:58 AM
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.

1 Answer, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 07 Jun 2013, 10:44 AM
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.

Tags
GridView
Asked by
Marcus
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or