Dynamically Change value of a text box when changing datagrid cells in C# WPF


This Content is from Stack Overflow. Question asked by Tharindu

I Need a help. I created a datagrid and the value column of that grid is automatically calculated When Entering the unit price and hours using INotifyPropertyChanged.(Please see the attached picture). But I don’t know how to get the Total value of that value column (sum of all values) automatically to total amount text box dynamically (Without using any button to calculate).( and also, if I delete a row then the value of that row should be automatically deducted from the Total amount.

enter image description here

Property Code :

public double UnitPrice
        get { return _UnitPrice; }
        set { _UnitPrice = value; OnPropertyChanged("UnitPrice"); OnPropertyChanged("Value"); }

    public double Hours
        get { return _Hours; }
        set { _Hours = value; OnPropertyChanged("Hours"); OnPropertyChanged("Value"); }

    public double Value
        get { return _Value = UnitPrice * Hours; }
        set { _Value = value; OnPropertyChanged("Value"); }

Your help is highly appreciated.

Thank you!


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?