/ Published in: C#
URL: http://windowsclient.net/learn/video.aspx?v=82523
The main thing you need to watch out for is implementing the INotifyPropertyChanged interface in order to force the DGV to update values that were affected by changing other values.
Code taken from the URL.
Expand |
Embed | Plain Text
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; //How to: Implement the INotifyPropertyChanged Interface //http://msdn.microsoft.com/en-us/library/ms229614.aspx namespace HDI_Winforms_BindableObjects { public partial class Form1 : Form { public Form1() { InitializeComponent(); LoadData(); } private void LoadData() { this.DataGridView1.DataSource = ProductList; } } public class OrderData : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { } } private string _ItemName; public string ItemName { get { return _ItemName; } set { _ItemName = value; } } private decimal _UnitPrice; public decimal UnitPrice { get { return _UnitPrice; } set { _UnitPrice = value; } } private int? _Quantity; public int? Quantity { get { return _Quantity; } set { _Quantity = value; NotifyPropertyChanged("Quantiy"); NotifyPropertyChanged("ExtPrice"); } } private DateTime? _OrderDate; public DateTime? OrderDate { get { return _OrderDate; } set { _OrderDate = value; NotifyPropertyChanged("OrderDate"); NotifyPropertyChanged("ShipDate"); } } public DateTime? ShipDate { } public decimal? ExtPrice { get { return _Quantity * _UnitPrice; } } public OrderData(string ItmName, decimal PriceEach, int? Qty, DateTime? OrdDate) { _ItemName = ItmName; _UnitPrice = PriceEach; _Quantity = Qty; _OrderDate = OrdDate; } } }
You need to login to post a comment.
