This blog is a knowledge base...where I clip cool tricks and urls

BindingList<T>

clipped from www.gavaghan.org

After reading Bil Simser’s discussion on DataTable vs. BindingList<T>, I’m convinced that BindingList<T> is the way to go for representing domain objects in C#. However, effective use of BindingList does require a certain amount of planning and forethought on the part of the developer. There are a number of things you can do to increase your chances of success with BindingList, but this post is about having your list items implement INotifyPropertyChanged in order to propagate change events through the BindingList itself.


using System.ComponentModel;



public class Account : INotifyPropertyChanged


{


private decimal balance;



public event PropertyChangedEventHandler PropertyChanged;



public decimal Balance


{


get


{


return balance;


}


set


{


balance = value;


if (PropertyChanged != null)


{


PropertyChanged( this, new PropertyChangedEventArgs(”Balance”) );


}


}


}


}


 blog it

No comments: