Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two instances of DataGrid on the same screen in a master-detail relationship.

The master DataGrid shows sections in an estimate and the detail DataGrid shows individual cost-items in the section. The master has a column that shows the subtotal for the section.

When I edit a cost-item value in the detail DataGrid, I obviously want the subtotal column on the master DataGrid to reflect this but I can't figure out how to get it to do this.

Elsewhere on the screen, I have a total for all the subtotals in all the sections (i.e. a grand total) and this is updated immediately, which is what I would expect because any changes in the model layer cause an event handler in the view-model to perform the following call with an empty string as parameter:

protected void OnPropertyChanged( [CallerMemberName] string propertyName = "" )
{
    PropertyChanged?.Invoke( this, new PropertyChangedEventArgs( propertyName ) );

My understanding is that firing the PropertyChanged event with an empty property name tells the binding engine to update all bindings, and indeed this does always seem to have been the case in the application so far.

How can I get a value in a cell of the master DataGrid to recognise that the value to which it is bound has changed? Is there a recognised way to do this?

What I have tried:

I've done a lot of looking for an answer to this but none seems to address the exact scenario I have above. I am surprised because this doesn't seem like an uncommon requirement to me.

I have also been thinking about hacking together something using event handlers in the UI layer but that's exactly what it feels like - hacking. There has to be a more elegant way?
Posted
Updated 20-Sep-19 22:40pm

1 solution

It appears the solution is indeed very simple. I've just stumbled across it while thinking, "I wonder what will happen if I change..."

The cost-items in the detail view were in an ObservableCollection but the sections to which the master DataGrid binds were a standard List. Changing the latter to also be an ObservableCollection fixed the problem.

I have to say that I am surprised, though. My understanding of the ObservableCollection was that it deals with the insertion and deletion of items and also the refreshing of the whole bound collection. I didn't think it was involved in the notification that a property of one item in the bound collection has changed. Clearly I am wrong.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900