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

Auto Update calculated field when property changes

1 Answer 105 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jagan k
Top achievements
Rank 1
Jagan k asked on 20 Nov 2010, 12:57 PM
i have a sample code which has a observable collection of items. if i enter qty/rate , total field should display qty * rate. but i can't get it. item collection is updated but not shown in the gridview. give suggestion to show the updated total field in radgridview when qty/rate changes. here is the code

namespace RadGridViewWPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            ObservableCollection<Item> items = new ObservableCollection<Item>();
            for (int i = 0; i < 10; i++)
            {
                items.Add(new Item() { ID = 1, ItemName = "Item" + i, Qty = 1, Rate = 12});
            }
 
            this.RadGridView1.ItemsSource = items;
        }
    }
 
    public class Item
    {
        private int _ID;
 
        public int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }
        private string _ItemName;
 
        public string ItemName
        {
            get { return _ItemName; }
            set { _ItemName = value; }
        }
        private decimal _Rate;
 
        public decimal Rate
        {
            get { return _Rate; }
            set { _Rate = value; }
        }
        private int _Qty;
 
        public int Qty
        {
            get { return _Qty; }
            set { _Qty = value; }
        }
        private decimal _Total;
 
        public decimal Total
        {
            get { return _Qty * _Rate; }
            set { _Total = value; }
        }
         
         
    }
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 22 Nov 2010, 08:15 AM
Hello,

 You need to implement INotifyPropertyChanged for your object (Item class). 

Regards,
Vlad
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
Tags
GridView
Asked by
Jagan k
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or