i was reading an article on two way data binding in winform and i tested their code which works fine. i was not aware about two way data binding in winform. here is article urlhttp://tech.pro/tutorial/776/csharp-tutorial-binding-a-datagridview-to-a-collection
please review my code and tell me am i on right direction? is there any other better option exist to achieve the same or complicated situation. just looking for guidance.
here is my full code
namespace PatternSearch{publicpartialclassForm2:Form{publicForm2(){InitializeComponent();}privatevoid btnBindData_Click(object sender,EventArgs e){BindingList<Car> cars =newBindingList<Car>();
cars.Add(newCar("Ford","Mustang",1967));
cars.Add(newCar("Shelby AC","Cobra",1965));
cars.Add(newCar("Chevrolet","Corvette Sting Ray",1965));
dataGridView1.DataSource= cars;}privatevoid btnUpdate_Click(object sender,EventArgs e){if(dataGridView1.DataSource!=null){BindingList<Car> cars = dataGridView1.DataSourceasBindingList<Car>;
cars.Where(d => d.Make=="Ford").First().Make="My Ford000";}elseMessageBox.Show("Grid has no data");}}publicclassCar:INotifyPropertyChanged{privatestring _make;privatestring _model;privateint _year;publiceventPropertyChangedEventHandlerPropertyChanged;publicCar(string make,string model,int year){
_make = make;
_model = model;
_year = year;}publicstringMake{
get {return _make;}set{
_make = value;this.NotifyPropertyChanged("Make");}}publicstringModel{
get {return _model;}set{
_model = value;this.NotifyPropertyChanged("Model");}}publicintYear{
get {return _year;}set{
_year = value;this.NotifyPropertyChanged("Year");}}privatevoidNotifyPropertyChanged(string name){if(PropertyChanged!=null)PropertyChanged(this,newPropertyChangedEventArgs(name));}}}
thanks