'BindingSource.ResetBindings not working unless "true" passed
I have a grid bound to a BindingSource (which is in turn bound to a List<T>). When I change the underlying List<T> data and then call:
bs.ResetBindings(false);
the grid does not get updated. But if I call:
bs.ResetBindings(true);
it does get updated. My code is now working but I'm still puzzled why this is necessary. According to MSDN the parameter to ResetBindings should be set to:
true if the data schema has changed; false if only values have changed
I certainly did not change any data schema... so why do I need true ?
Solution 1:[1]
If you have two types: Cat and Dog that both derive from Animal. This will not work properly:
from Designer.cs
animalBindingSource1.DataSource = typeof(Animal);
and then in in e.g Form_Load
List<Cat> cats = getCats();
animalBindingSource1.DataSource = cats;
Try using a BindingList, e.g.
animalBindingSource1.DataSource = new BindingList<Animal>(cats);
Post your code if it doesn't work. There's probably nothing wrong with the devexpress gridcontrol.
Solution 2:[2]
Just do it like this:
bs.DataSource = ListOfMyObjectOrWhatEver; //EVEN IF ALREADY MADE!
bs.ResetBindings(false);
grid.Refresh();
Hope it helps...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Martin |
| Solution 2 | Ricardo Rodrigues |
