What is the advantage of using DataSourceUpdateMode.OnPropertyChanged for databinding winform c# -


first see code

public class car : inotifypropertychanged     {         private string _make;         private string _model;         private int _year;          public event propertychangedeventhandler propertychanged;          public car(string make, string model, int year)         {             _make = make;             _model = model;             _year = year;         }          public string make         {             { return _make; }             set             {                 _make = value;                 this.notifypropertychanged("make");             }         }          public string model         {             { return _model; }             set             {                 _model = value;                 this.notifypropertychanged("model");             }         }          public int year         {             { return _year; }             set             {                 _year = value;                 this.notifypropertychanged("year");             }         }          private void notifypropertychanged(string name)         {             if (propertychanged != null)                 propertychanged(this, new propertychangedeventargs(name));         }     } 

this way binding

public partial class form1 : form     {         public form1()         {             initializecomponent();         }          bindinglist<car> ol;          private void form1_load(object sender, eventargs e)         {             car cartest = new car("ford", "mustang", 1967);             ol = new bindinglist<car>();             ol.add(cartest);              this.textbox1.databindings.add("text", ol, "make", true, datasourceupdatemode.onpropertychanged);             this.textbox2.databindings.add("text", ol, "make", true, datasourceupdatemode.onpropertychanged);             this.textbox3.databindings.add("text", ol, "make");              datagridview1.datasource = ol;         }          private void button1_click(object sender, eventargs e)         {             ol.where(d => d.make == "ford").first().make = "my ford000";         }      }  use `datasourceupdatemode.onpropertychanged` 1 textbox , did not use other textbox  this.textbox2.databindings.add("text", ol, "make", true, datasourceupdatemode.onpropertychanged); this.textbox3.databindings.add("text", ol, "make"); 

when change value in 1 textbox change reflected in other textbox without using datasourceupdatemode.onpropertychanged not understand advantage of datasourceupdatemode.onpropertychanged

even when change data in data source below way change reflected in textboxes.

ol.where(d => d.make == "ford").first().make = "my ford000";  please me understand right usage of `datasourceupdatemode.onpropertychanged` when , use. 

thanks

when adding binding in following way:

textbox3.databindings.add("text", ol, "make"); 

it uses datasourceupdatemode.onvalidation, can check here. so, if have validation rules control, underlying value won't updated if validation fails. on other side datasourceupdatemode.onpropertychanged update underlying source in case.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -