When i update object, add object into the collection, the grid refreshed successfully.
BindingList improved in new version? Could you please advise.
public partial class DataInGridDemo : Form
{
public DataInGridDemo()
{
InitializeComponent();
}
BindingList<MyCustomClass> list2;
private void DataInGridDemo_Load(object sender, EventArgs e)
{
list2 = new BindingList<MyCustomClass>() { new MyCustomClass(), new MyCustomClass() };
this.dataGridView1.DataSource = list2;
}
private void button1_Click(object sender, EventArgs e)
{
list2[0].X = 88888;
list2[1].s = "going";
list2.Add(new MyCustomClass());
list2[2].s = "aassssssss1213";
}
}
public class MyCustomClass //: INotifyPropertyChanged
{
private int x;
public int X
{
get
{
return x;
}
set
{
x = value;
//if (PropertyChanged != null)
// PropertyChanged(this, new PropertyChangedEventArgs("X"));
}
}
public string s { get; set; }
#region INotifyPropertyChanged Members
//public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
{
public DataInGridDemo()
{
InitializeComponent();
}
BindingList<MyCustomClass> list2;
private void DataInGridDemo_Load(object sender, EventArgs e)
{
list2 = new BindingList<MyCustomClass>() { new MyCustomClass(), new MyCustomClass() };
this.dataGridView1.DataSource = list2;
}
private void button1_Click(object sender, EventArgs e)
{
list2[0].X = 88888;
list2[1].s = "going";
list2.Add(new MyCustomClass());
list2[2].s = "aassssssss1213";
}
}
public class MyCustomClass //: INotifyPropertyChanged
{
private int x;
public int X
{
get
{
return x;
}
set
{
x = value;
//if (PropertyChanged != null)
// PropertyChanged(this, new PropertyChangedEventArgs("X"));
}
}
public string s { get; set; }
#region INotifyPropertyChanged Members
//public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
VulpesPosted May 29, 2012, 9:24 AM
The only reason why the changes to the first 2 elements of the BindingList are being persisted immediately to the DGV is because you're adding a new element just after these changes are made.
Additions to or deletions from the BindingList cause the DGV's databinding to be refreshed immediately but changes to the items do not cause a refresh unless the business class implements INotifyPropertyChanged.
So the position is in fact what we always thought it was ;)
VulpesPosted May 29, 2012, 7:14 AM
However, I've just tried your example and it seems that it's not necessary after all!
Although I'm not aware of any recent changes to the BindingList