I had a problem that was partially solved. To explain it quickly : I have a grid binded to a complex object that require to be serialized. When the object is build back from the serialization, event like on the grid doesn't refresh the table display. Someone told me to rebuild the event once unserialize, it works! But the event that refresh the grid doesn't seems to fire at all.
I had to build an event from my complex object that told me that something change inside. From this event I added this code :
this.bindingSource1.ResetBindings(false);
The problem is the grid is flipping and the user doesn't have a good feeling (rows are moving up and down and than stop).
How can I reset the binding without having this kind of flipping? How can I solve the original problem? (This will solve automaticly everything).
Update
Here is an example that do exactly the same behavior:
Create a class:
[Serializable()]
class BOClient : INotifyPropertyChanged, IDataErrorInfo
{
private string name;
private int len;
public string Name
{
get { return name; }
set { name = value;
this.len = name.Length;
if (this.PropertyChanged !=null)
this.PropertyChanged(this, new PropertyChangedEventArgs("Name"));
}
}
public int Len
{
get { return this.len; }
}
public BOClient(string name)
{
this.Name = name;
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region IDataErrorInfo Members
public string Error
{
get { return ""; }
}
public string this[string columnName]
{
get { return ""; }
}
#endregion
}
Now, create a form with a BindingSource call "bindingSource1" and go use the class as datasource. Create a grid and bind the grid to the bindingsource1.
In that form use this code in the load :
private void Form1_Load(object sender, EventArgs e)
{
BindingList<BOClient> listClient = new BindingList<BOClient>();
listClient.Add(new BOClient("P1"));
listClient.Add(new BOClient("P2"));
listClient.Add(new BOClient("P3"));
//using (MemoryStream mem = new MemoryStream())
//{
// BinaryFormatter b1 = new BinaryFormatter();
// try
// {
// b1.Serialize(mem, listClient);
// }
// catch (Exception ez)
// {
// MessageBox.Show(ez.Message);
// }
// BinaryFormatter b2 = new BinaryFormatter();
// try
// {
// mem.Position = 0;
// listClient = (BindingList<BOClient>)b2.Deserialize(mem);
// }
// catch (Exception ez)
// {
// MessageBox.Show(ez.Message);
// }
//}
this.bindingSource1.DataSource = listClient;
}
I put the serialization process in comment BECAUSE it seems that it do the same weird behavior without it... now start the application. Change a name of a client. Example "p1" for "New name" and click the cell under the changed one. You will see the "len" column NOT changing. BUT if you click the cell that has the len you will see the number changing to the right value.
Any one have an idea why?