M
Mou_kolkata
Guest
first see my 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
{
get { return _make; }
set
{
_make = value;
this.NotifyPropertyChanged("Make");
}
}
public string Model
{
get { return _model; }
set
{
_model = value;
this.NotifyPropertyChanged("Model");
}
}
public int Year
{
get { return _year; }
set
{
_year = value;
this.NotifyPropertyChanged("Year");
}
}
private void NotifyPropertyChanged(string name)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
this way i am 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";
}
}
i use DataSourceUpdateMode.OnPropertyChanged for one textbox and did not use for other textbox
this.textBox2.DataBindings.Add("Text", ol, "Make", true, DataSourceUpdateMode.OnPropertyChanged);
this.textBox3.DataBindings.Add("Text", ol, "Make");
when change value in one textbox the change is reflected in other textbox too without using DataSourceUpdateMode.OnPropertyChanged so just do not understand the advantage of DataSourceUpdateMode.OnPropertyChanged
even when change data in data source by the below way then change is also reflected in all textboxes.
ol.Where(d => d.Make == "Ford").First().Make = "My Ford000";
please help me to understand right usage of DataSourceUpdateMode.OnPropertyChanged like when and where to use.
thanks
Continue reading...
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
{
get { return _make; }
set
{
_make = value;
this.NotifyPropertyChanged("Make");
}
}
public string Model
{
get { return _model; }
set
{
_model = value;
this.NotifyPropertyChanged("Model");
}
}
public int Year
{
get { return _year; }
set
{
_year = value;
this.NotifyPropertyChanged("Year");
}
}
private void NotifyPropertyChanged(string name)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
this way i am 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";
}
}
i use DataSourceUpdateMode.OnPropertyChanged for one textbox and did not use for other textbox
this.textBox2.DataBindings.Add("Text", ol, "Make", true, DataSourceUpdateMode.OnPropertyChanged);
this.textBox3.DataBindings.Add("Text", ol, "Make");
when change value in one textbox the change is reflected in other textbox too without using DataSourceUpdateMode.OnPropertyChanged so just do not understand the advantage of DataSourceUpdateMode.OnPropertyChanged
even when change data in data source by the below way then change is also reflected in all textboxes.
ol.Where(d => d.Make == "Ford").First().Make = "My Ford000";
please help me to understand right usage of DataSourceUpdateMode.OnPropertyChanged like when and where to use.
thanks
Continue reading...